Ok, I figured it all out but now cant climb stairs.
I will explain
So When we collect the old position first the y must match the new y and also match the raycast amount in order to be directly on the floor.
Here is a good example
This took me a whole day to figure out.
Now how to figure out a way to climb the stairs.
rem Old position
oldx#=GetobjectX(OriginalSoldier)
oldy#=GetobjectY(OriginalSoldier) -10.0
oldz#=GetobjectZ(OriginalSoldier)
rem Gravity on camera
if jump=0 then SetobjectPosition(OriginalSoldier,getobjectx(OriginalSoldier),getobjecty(OriginalSoldier)-1,getobjectz(OriginalSoldier))
rem do moving code here
newx#=GetObjectRayCastSlideX(0)
newy#=GetObjectRayCastSlideY(0) -10.0
newz#=GetObjectRayCastSlideZ(0)
raycast=10.00
rem Adjust Y to match floor
if ObjectSphereSlide(0,oldx#,oldy#,oldz#,newx#,newy#,newz#,raycast)>0
newx#=GetObjectRayCastSlideX(0)
newy#=GetObjectRayCastSlideY(0)-10.00 rem we add this line here to place object back to floor, if we are under the raycast there is no collision.
newz#=GetObjectRayCastSlideZ(0)
SetobjectPosition(OriginalSoldier,newx#,newy# ,newz#)
endif