Rotate/move based on DT

Get help using Construct 2

Post » Wed May 08, 2013 5:00 pm

The only way I've ever moved objects manually is by using the update function, ie: "Every tick set position to self.x + 1" but I'm in a situation where I really need the object to move based on time (like if you slow down the time scale, the motion will also slow down). This is probably simple but I've never done it. What's the best way?
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Wed May 08, 2013 6:15 pm

@sushin - Very similar to what you have here, but you want to think in terms of an objects speed per second and then adjust according to dt.

So in your example above - Every tick set position to self.x + 1 - you're basically saying the object is moving 60 pixels per second BUT only if you have a frame rate of 60 fps.

To convert that to framerate independent movement, you would have the following:
Every tick set position to self.x + (SPEED_PER_SECOND * dt)

That calculates how far the character should move, based on their SPEED_PER_SECOND (which could be hardcoded, or better, an instance variable) in the time that has passed (dt) and adds that to its position.

Hope that makes sense...
rogueNoodle2013-05-08 18:17:38
B
9
S
3
G
4
Posts: 63
Reputation: 3,083

Post » Wed May 08, 2013 6:17 pm

Ah. I remember now. Thank you for the information. =)
B
10
S
3
G
3
Posts: 234
Reputation: 3,467


Return to How do I....?

Who is online

Users browsing this forum: randomly, Walessio, Yahoo [Bot] and 22 guests