How do I stop my sprite from moving, despite the acceleration being 0?

0 favourites
  • 2 posts
From the Asset Store
Minimal Sprite Font with Stroke for Pixel Art games.
  • Hey, so I created an instance variable "Acceleration" for my sprite. I've made it so that every tick the sprite looks at the mouse and every tick the sprite moves forward negative sprite.Acceleration pixels. (Initial value for Acceleration is 0)

    I've also set the Acceleration to clamp(sprite.Acceleration,0,5) every tick.

    When left mouse button is down 1 is added to "Acceleration" else 0.1 is subtracted from "Acceleration".

    When I preview, if I press LMB it moves away from the mouse and slows down to 0 the way I want. But when I'm not pressing LMB it keeps moving towards the mouse.

    I made a text object to display "Acceleration", in which it shows it to be 0 when LMB is not pressed.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Events are executed from top to bottom.

    So what happens is your event #3 subtracts 0.1 from acceleration and its value becomes (-0.1)

    Then on the next tick the sprite is moved +0.1px towards the mouse, and only then clamp() changes its value to 0.

    You simply need to change the order of events and actions.

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