# Need some help with dt

Get help using Construct 2

### » Sat Apr 19, 2014 3:28 pm

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)
B
4
Posts: 11
Reputation: 236

### » Sat Apr 19, 2014 3:34 pm

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?
B
23
S
4
G
1
Posts: 72
Reputation: 8,348

### » Sat Apr 19, 2014 4:07 pm

@LevelUpJordan

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?
B
4
Posts: 11
Reputation: 236

### » Sat Apr 19, 2014 4:18 pm

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).
B
23
S
4
G
1
Posts: 72
Reputation: 8,348

### » Sat Apr 19, 2014 4:21 pm

@LevelUpJordan

OH, absolutely amazing,

B
4
Posts: 11
Reputation: 236

### » Sat Apr 19, 2014 4:21 pm

No problem
B
23
S
4
G
1
Posts: 72
Reputation: 8,348