# Animation frame based on mouse position?

Get help using Construct 2

### » Sun Feb 10, 2013 8:46 pm

I'm trying to change an animation frame based on the mouse's position relative to the object.

I believe I've been through all the events and actions and searched Google multiple times. I just can't find a combination or answer that'll do what I'm looking for.

Here's a couple of frames of my player object:

As you can see, "Set angle toward position" just doesn't cut it
Say the mouse is at an angle of 90 relative to the object, it would show the first picture. And so on...

How would I go about doing something like this?
B
3
Posts: 2
Reputation: 554

### » Mon Feb 11, 2013 8:16 pm

@Wakey

One non mathematical way of doing it, is to create 4 triangle sprites. One representing North South East West (imagine creating a giant X over the middle of the screen)

Then use

On mouse over "North" set animation to "player north" etc

then make the triangles invisible so you can't see them.

Here's an awesome sketch
http://imgur.com/h1mb2mU

This assumes your player is always in the center of the screen though.justifun2013-02-11 20:20:01
B
91
S
44
G
17
Posts: 1,012
Reputation: 18,572

### » Mon Feb 11, 2013 8:22 pm

If the player ISNT in the center of the screen, here's another way of doing it.

create 4 events

mouseAbsolute.X > player. X
AND
mouseAbsolute Y > player.Y

-> set animation player to "north"

MouseAbsoute.X < player.Y
AND
mouseAbsolute.Y < player.Y

set animation player to "south"

etc etc

Make a event check all 4 locations based on the players postion, top left, top right, bottom left, bottom right.

then change the animation based on that.

only 1 will be true at any given time.
B
91
S
44
G
17
Posts: 1,012
Reputation: 18,572

### » Mon Feb 11, 2013 8:33 pm

Or You could check if angle between sprite and mouse is between certain value.
B
160
S
69
G
44
Posts: 2,611
Reputation: 36,844

### » Mon Feb 11, 2013 8:49 pm

Check out this thread. I think that'll cover what you need.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452