Moving and DT

  • 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?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • What's the difference between moving to XY and moving to delta XY in the moveto behavior?

  • I think the difference is that move to XY moves to a specific co-ordinate whereas delta XY moves relative to the starting position.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)