YouGroove Posted January 27, 2015 Share Posted January 27, 2015 I made a simple translate code using PhysicsSetPosition I put the script below on some character with a simple solid cylinder physics (no character physics) , the character moves fast then after some time it slows down , then it regains speed after some seconds. (i had same thing happen with space ships in the air and not gravity) Is there something particular to do to keep a constant speed throught time ? Or is this due to physics ? Script.speedX = 0.5 function Script:Start() end function Script:UpdateWorld() end function Script:UpdatePhysics() local window = Window:GetCurrent() local xposition = 0 if window:KeyDown(Key.Q) then xposition =1 end if window:KeyDown(Key.D) then xposition = -1 end local pos= self.entity:GetPosition(true) pos.x= pos.x + (xposition * self.speedX * Time:GetSpeed()) self.entity:PhysicsSetPosition(pos.x,pos.y,pos.z ,1) end Quote Stop toying and make games Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 27, 2015 Share Posted January 27, 2015 When setting values for physics options, you don't have to multiply with Time:GetSpeed() Since physics are already updated a fixed amount of times per second. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted January 27, 2015 Author Share Posted January 27, 2015 My bad, it was some programming behaviour i found comparing two models moving at same time one with PhysicsSetPosition, another with SetPosition. The right script don't have to call GetPosition inside PhysicsLoop , because you need a constant absolute position throught time when moving, and force the object position with PhysicsSetPosition. The good script : Script.speedX = 0.5 function Script:Start() self.entity:SetGravityMode(false) self.pos = self.entity:GetPosition(true) end function Script:UpdatePhysics() local window = Window:GetCurrent() local xposition = 0 if window:KeyDown(Key.Q) then xposition =1 end if window:KeyDown(Key.D) then xposition = -1 end self.pos.x= self.pos.x + (xposition * self.speedX * Time:GetSpeed()) self.entity:PhysicsSetPosition(self.pos.x,self.pos.y, self.pos.z ,0.5) end When setting values for physics options, you don't have to multiply with Time:GetSpeed() Since physics are already updated a fixed amount of times per second. ok, i'll take it in account Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.