SFML community forums

Help => General => Topic started by: MarbleXeno on January 24, 2021, 01:50:34 pm

Title: [fixed] Can't stop the sprite from moving
Post by: MarbleXeno on January 24, 2021, 01:50:34 pm
Hi. Im creating simple game and i implemented this move script. I want to stop my sprite from moving but it actually never stops. I printed the velocity.x in terminal and it shows random numbers.

How can i stop my sprite from moving in a correct smooth way? i'm struggling with this for a long time.

//code
(click to show/hide)

//what terminal prints when the sprite should stop moving
(click to show/hide)

Title: Re: Can't stop the sprite from moving
Post by: G. on January 24, 2021, 02:32:11 pm
Hey.
They are not random numbers, they are very tiny numbers written in scientific notation.
3.22666e-12 means 3.22666 * 10^-12 which means 0.00000000000322666...

Set your velocity to 0 when it is very close to 0 and isMoving is false.
Something like < to 0.01 and > to -0.01 or whatever feels good to your game.
Title: Re: Can't stop the sprite from moving
Post by: MarbleXeno on January 24, 2021, 03:00:00 pm
Thanks, it was so obvious and easy!  The final code:
(click to show/hide)