# Set velocity (measured in pixels per second)

What is the best way to create movement that smoothly moves at a certain number of pixels per second?

Thanks

The “smoothly” visual sensation is measured in frames per second (fps) not pixels. A good FPS starts at 25 (“Smooth” movement perception for the human eye starts at 24 when it loses the perception of frames and is tricked to perceive the sequences as moviment). Most games focus on 60 fps ( ~ double of NTSC speed ). 3D games focus on 120fps (to be divided in 2 interleaved images at 60fps (left/right eye). Forget pixes per second. You need to measure “entire images” formed per second (fps).

Sorry. Reading this straight off the documentation of a game engine.

This is what I meant:
‘The maximum velocity in pixels per second sq. that the Body can reach.’, quoted from Phaser game engine docs at http://docs.phaser.io/Phaser.Physics.Arcade.Body.html#velocity

THANKS

I need the behaviour of the game engine to be mimicked exactly (in this case).

I want the user to be able to preview the movement before they apply that to the game.

THANKS AGAIN

The pointed parameter does not fit in the request “pixels per second to make a smooth movement”

To be true, the pointed parameter is expressed in pixels per second squared (acceleration), not pixels per second (speed).

I am pretty sure your request does not have a precise answer. It’s attached to what you intend to do. The smooth speed of a bullet is not the same of a snail and in a fixed. And at some fixed speed in a fictional world with no friction the acceleration could be set to zero. Make experiments with your library.

You will have to calculate the new position taking into account the time elapsed from a reference position and the corresponding time (can be the previous position):

New_Position= old_position+speed*elapsed_time_since_previous_position

As a side note, “pixels per second sq.” is not correct for speed (as Rick explained).

Julen

[quote=95607:@Julen Ibarretxe Uriguen]You will have to calculate the new position taking into account the time elapsed from a reference position and the corresponding time (can be the previous position):

New_Position= old_position+speed*elapsed_time_since_previous_position

As a side note, “pixels per second sq.” is not correct for speed (as Rick explained).

Julen[/quote]

[quote=95606:@Rick Araujo]The pointed parameter does not fit in the request “pixels per second to make a smooth movement”

To be true, the pointed parameter is expressed in pixels per second squared (acceleration), not pixels per second (speed).

I am pretty sure your request does not have a precise answer. It’s attached to what you intend to do. The smooth speed of a bullet is not the same of a snail and in a fixed. And at some fixed speed in a fictional world with no friction the acceleration could be set to zero. Make experiments with your library. :)[/quote]
Thanks. You two.

Oliver, is there an acceleration? I would say so since you have a “maximum speed”.

If you also need to take into account the acceleration the expression should be as follows:

new_position= old_position + old_speedelapsed_time + 0.5accelerationelapsed_time^2
and new_speed=old_speed + acceleration
elapsed_time, which you will need for the calculation of the next position.

If the acceleration corresponds to the gravity, then you will only need to apply it in the vertical direction.

Julen

[quote=95629:@Julen Ibarretxe Uriguen]Oliver, is there an acceleration? I would say so since you have a “maximum speed”.

If you also need to take into account the acceleration the expression should be as follows:

new_position= old_position + old_speedelapsed_time + 0.5accelerationelapsed_time^2
and new_speed=old_speed + acceleration
elapsed_time, which you will need for the calculation of the next position.

If the acceleration corresponds to the gravity, then you will only need to apply it in the vertical direction.

Julen[/quote]
By smooth I don’t mean acceleration. I meant with a high FPS.

THANKS

[quote=95629:@Julen Ibarretxe Uriguen]Oliver, is there an acceleration? I would say so since you have a “maximum speed”.

If you also need to take into account the acceleration the expression should be as follows:

new_position= old_position + old_speedelapsed_time + 0.5accelerationelapsed_time^2
and new_speed=old_speed + acceleration
elapsed_time, which you will need for the calculation of the next position.

If the acceleration corresponds to the gravity, then you will only need to apply it in the vertical direction.

Julen[/quote]

[quote=95629:@Julen Ibarretxe Uriguen]Oliver, is there an acceleration? I would say so since you have a “maximum speed”.

If you also need to take into account the acceleration the expression should be as follows:

new_position= old_position + old_speedelapsed_time + 0.5accelerationelapsed_time^2
and new_speed=old_speed + acceleration
elapsed_time, which you will need for the calculation of the next position.

If the acceleration corresponds to the gravity, then you will only need to apply it in the vertical direction.

Julen[/quote]
I will probably be adding acceleration as well though. Thanks

Technically speaking, a good relative measure, based on common resolution (which may vary) is 1297152 pixels per second is relative to the speed of a bullet.

If you want something to move at 100 pixels per second, then if you are getting exactly 25fps, it would move at
100/25 = 4 pixels every refresh

If you don’t know what refresh rate you are going to get, then you need to know how long a timespan has elapsed since the last refresh to know where the object should be.

e.g. if you draw, then the next refresh occurs 1/40 of a second later, then the new position would be
100 / 40 = 2.5 pixels from the last position.
Whether you round up or down would be up to you.