How do I get the angle at which a sprite is moving?

0 favourites
  • 5 posts
From the Asset Store
Minimal Sprite Font with Stroke for Pixel Art games.
  • Hello, My name is Ben and I find this game engine to be awesome!

    I am making a shoot 'em up game and I have a sprite that gets moved when a user "is in touch".

    My question is, how do I get the angle value that the sprite is heading to?

    I have tried making a compass with an object in the middle of the screen and an object bar on the sprite (which pointed to the object on the centre of screen) but that did not work well.

    Is there an easier way to get the angle?

  • Hi Benydc,

    you can get the angle of an object via the expression panel.

    Like:

    Event: Every Tick

    Action: Set global variable to...

    Then a dialog pops open where you can set the value. Plus the expression

    panel opens up. If you click into the value field you can select the object from

    the expressions panel. The first expression in this list is "Angle" (Get the

    object´s current angle, in degrees).

    Hope that helps.

    Greetings

    Soulsliver

  • Hello Soulsliver,

    I have tried that before but it only gets the angle of which the sprite is rotated at. (it is set to 270 degrees so it will always point to that)

    Check attachment for example.

  • Create 2 instance variables on the object called something like PreviousX and PreviousY

    On start of layout

    --- Set Object.PreviousX to Object.X

    --- Set Object.PreviousY to Object.Y

    Every tick

    --- Angle of Motion = angle(Object.PreviousX, Object.PreviousY, Object.X, Object.Y)

    --- Set Object.PreviousX to Object.X

    --- Set Object.PreviousY to Object.Y

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That has worked!

    Thank you zatyka!

    Ben C.

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