Mouse Click movement set "direction" of sprite

  • How do I make it so when I click it determines which way I am moving so I can tell it which animation to play. I am using rex_moveto target position of object behavior to do the mouse click movement. I am doing a roguelike movement system.

    I'm new to Construct and new to the forums so idk what all is needed to get a question answered, but let me know and I will edit it into the main post.

  • compare the location of the moving object to the location of the click.

    object.x < click.x = to the left it should face right.

    object.y < click.y = to the top it should face down.

    etc. then play the right animation

  • That is the first thing I tried, but it liked to animate up and down when I was going left or right. Only doing two directions works perfect, but once I add all four directions it doesn't work correctly

  • I like this method:

    On Left Mouse Button Down

    --> Set Angle of Motion = round(angle(object.X, object.Y, mouse.X, mouse.Y) / 90) * 90

    If you wanted it 4 way, it'd be 90 (90 * 4 = 360). If you wanted it 8 way, then you'd change 90 to 45 (45 * 8 = 360). It will go to whatever the closest angle is. Then I like to do:

    If Moving

    Compare Object.8Direction.Angle of Motion = 0

    --> Set Animation Walk Right

    Compare Object.8Direction.Angle of Motion = 90

    --> Set Animation Walk Down

    Compare Object.8Direction.Angle of Motion = abs(180)

    --> Set Animation Walk Left

    Compare Object.8Direction.Angle of Motion = -90

    --> Set Animation Walk Up

    There are more ways to do it, but I like that method well enough.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Using angle of motion rotates my sprite. I am doing it now by comparing the player position and two imagepoints. It is working pretty well so far.

  • SYNYST3R1, can I have a cap.x file of only the code you used to rotate your sprite?

  • cloud.mail.ru/public/96c41d239a ... oving.capx

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