Moving and DT

Get help using Construct 2

Post » Wed May 24, 2017 9:20 am

If I wanted an object to move exactly 16 pixels by the end of its movement and had it move 1 pixel per frame with DT as part of the equation, how do I ensure it ends up exactly 16 pixels away?
B
45
S
13
G
1
Posts: 236
Reputation: 4,010

Post » Wed May 24, 2017 10:19 am

Hi @corlenbelspar,

If you're using dt to modify the object's movement (e.g. every tick add 1*60*dt to object.X) then you're most likely not going to get it moving at exactly 1 pixel per frame, because dt usually isn't an exact 60th of a second.

There are a number of 3rd party plugins that will allow you to move something an exact distance over time, such as the MoveTo plugin, but if you're just using the core behaviours, you could do something like this, using right movement as an example:

Add an instance variable to your object, targetX and a boolean, moveRight

is moveRight true:
>>trigger once: set object.targetX to self.X+16
>>Every tick if object.X<self.targetX, add self.X+1*60*dt to object

If object.X>=self.targetX set object to self.targetX; set moveRight false

This will at least ensure that you end up exactly 16 pixels away, factoring in dt, but you won't be moving exactly one pixel per frame.

You can also turn on pixel rounding in the project properties and this will draw the sprite to integer pixel values, but the actual X of the object will be a float.
B
19
S
8
G
3
Posts: 429
Reputation: 3,972

Post » Wed May 24, 2017 10:23 am

@corlenbelspar

Also you could use the bullet behaviour, using the "compare distance travelled" condition to stop movement after 16 pixels, setting the speed to 60 pixels per second.
B
19
S
8
G
3
Posts: 429
Reputation: 3,972

Post » Sun Jun 04, 2017 11:52 am

What's the difference between moving to XY and moving to delta XY in the moveto behavior?
B
45
S
13
G
1
Posts: 236
Reputation: 4,010

Post » Sun Jun 04, 2017 1:12 pm

I think the difference is that move to XY moves to a specific co-ordinate whereas delta XY moves relative to the starting position.
B
19
S
8
G
3
Posts: 429
Reputation: 3,972


Return to How do I....?

Who is online

Users browsing this forum: Lancifer, nahima and 11 guests