How to change animation depending on mouse click\position

Get help using Construct 2

Post » Fri Apr 04, 2014 6:12 am

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:
Image

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
Creator of MiniDayZ
B
22
S
2
G
2
Posts: 75
Reputation: 1,858

Post » Fri Apr 04, 2014 7:44 am

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....)
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,882

Post » Fri Apr 04, 2014 9:10 am

RamPackWobble wrote: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
Creator of MiniDayZ
B
22
S
2
G
2
Posts: 75
Reputation: 1,858

Post » Fri Apr 04, 2014 9:32 am

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.
You do not have the required permissions to view the files attached to this post.
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,882


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests