Jump to content

PhysicsSetPosition slow down


YouGroove
 Share

Recommended Posts

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

Stop toying and make games

Link to comment
Share on other sites

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 smile.png

Stop toying and make games

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...