How to change animation depending on mouse click\position

0 favourites
  • 5 posts
From the Asset Store
Simplistic hyper-casual game with nature elements. Tap to switch between the 4 elements and reach a better score.
  • Hi people, I have a char with 4 animations (look up\left\right\down). i need to switch between animations, depending on mouse position on click.

    That example of what i need:

    i know one method, with sprites for each direction and check if clicked to switch. But i need another method, based on mouse click X&Y only

  • Find angle to mouse ( angle(player.x,player.y,mouse.x,mouse.y) ) and use that to decide the required animation ? (if angle is between....)

  • Find angle to mouse ( angle(player.x,player.y,mouse.x,mouse.y) ) and use that to decide the required animation ? (if angle is between....)

    Already tried it, its not working correctly. Angle to mouse always between -180 +180. You can check it by yourself

  • If the angle is minus (ie above/anticlockwise) all you need to do is add it to 360 degrees and go from there.

    The only other slight problem is pointing to the right as you cant say is the angle between 315 and 45 degrees so you need to use an "OR"

    is the angle greater than 315 OR is the angle less than 45 then it is pointing right.

    Anyway it appears to work - althought there are other (better ?) ways to do this.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's been a while since nobody talked here, but I have a similar issue. Trying not to fill the forum with duplicated topics.

    I am developing a strategy board war game, Civilization/AoE like. The board is a tilemap.

    You select which troop to move by pressing/clicking on the instance and then dragging/clicking/pressing on the destination tile.

    After you have selected the active troop, I would like an arrow to be shown from the troop towards the destination tile. So, if you get further from the troop, the arrow lengthens.

    I have read people doing similar thing by changing the animation, yet that would require having, let's say 10 differents sprites, each one a tile longer, just for that. Is it not possible to call a specific frame of the animation according to position? Being that the case, I could just have an arrow sprite, being each frame an arrow a tile longer.

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