Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [fixed] Can't stop the sprite from moving  (Read 1442 times)

0 Members and 1 Guest are viewing this topic.

MarbleXeno

  • Guest
[fixed] Can't stop the sprite from moving
« 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)

« Last Edit: January 24, 2021, 03:00:17 pm by MarbleXeno »

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Can't stop the sprite from moving
« Reply #1 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.

MarbleXeno

  • Guest
Re: Can't stop the sprite from moving
« Reply #2 on: January 24, 2021, 03:00:00 pm »
Thanks, it was so obvious and easy!  The final code:
(click to show/hide)