-
I wanted to create a simple sliding door (the kind you see at the entrance of your local supermarket). I looked at the following discussion which explained that to properly move the body I needed to use This is roughly how I move the object in my code: -- Called once per frame while the door is moving
function Door.Update( Deltatime )
if Animation.Time < Animation.TimeMax then
Animation.Time = Animation.Time + Deltatime
-- Animation progress from 0 to 1
TimeElapsed = Animation.Time / Animation.TimeMax
TimeElapsed = math.clamp( TimeElapsed, 0.0, 1.0 )
-- Inverse animation to close door if already open
if IsOpen then
TimeElapsed = 1.0 - TimeElapsed
end
TempVec1 = Position + DirectionAxis * Distance
TempVec1 = Lerp( Position, TempVec1, TimeElapsed )
BodyMoveKinematic(
Body,
TempVec1,
Rotation,
math.max( ENGINE_DELTATIME, 0.001 )
)
end
end So basically I use |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
MoveKinematic
will calculate the velocity needed to go from where you are to the desired position in the desired delta time (= usually a single physics update). The physics engine will never change the velocity of a kinematic body, you need to do this yourself. If you stop callingMoveKinematic
the body will continue moving at the same speed forever. If you want the body to stop after arriving then callBodyInterface::SetLinearAndAngularVelocity(body_id, Vec3::sZero(), Vec3::sZero())
.