0 Favourites

# Need some help with dt

• 6 posts
• Hello,

I'm new to the scirra forums and construct2 but recently joined after someone showed me some cool things you can make with the game engine. But to get to the point, I have some questions about dt.

I think I have a basic understanding of how its used but I can't seem to fully grasp it. Lets say I want to move an object like this:

Event: Every Tick--> Sprite set Y--> to sprite.Y+5

I know there are behaviors that come with dt, but I would like to move the object this way for a scenario in the game. I would like to move the object 5 pixels down. The problem is it's not always fast unless I add dt but even so I can't seem to get it right. I would like for it to run as fast as possible on different systems and devices but have it move at 5 pixels.

So I was wondering if I would set the sprite's Y position to sprite.Y + (300*dt)

Or would it be sprite.Y + (500*dt)?

I assumed it would be 300 since multiplying 5*60 gives 300. So every 60 seconds the sprite would move 300 pixels which would be 5 pixels a second?

Or am I wrong? I find dt a bit confusing so I would appreciate it if someone could tell me how I can move a sprite object by 5 with dt. (Sprite.Y+5)

• If in 60 seconds you wanted to move 300 pixels the equation you want is sprite.Y + (300/60*dt) = sprite.Y + (5*dt)

dt is the time that has passed since the last frame so in 1 second the sum of dt will equal 1

Does that make sense?

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Hello, I appreciate your example it does make alot more sense (I think). So does that mean if I change the equation to sprite.Y + (300/30*dt), then the sprite object will move 300 pixels in 30 seconds?

I was wondering how I could make the sprite object move 5 pixels every 0.2 seconds using dt every tick?

• Yes! Exactly that, sprite.Y+(300/30*dt) will move 300 in 30 seconds

We can use the same logic for this second problem. The distance moved is (distance/time*dt), in this case 5/0.2*dt which is equal to 25*dt, so if it's still moving downwards we would use sprite.Y+(25*dt).

• OH, absolutely amazing,