# Detect Angle of Mouse?

0 favourites
• 4 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
• Hello. I've run into a bit of a dead end with an idea I had and was hoping someone could perhaps point me in the direction of a solution (Or at least tell me if it's outright impossible).

In my game I'd like the player to weild a whip which they can aim with the mouse cursor. This in itself is easy; I just have to spawn the whip at an image point of my choosing and set the angle of the whip to Mouse.X,Mouse.Y... but the tricky part is the animation itself. You see, it would look silly if the player wanted to whip upwards, for instance, and the animation showed the motion of the player whipping downwards. That's why I need some kind of way to detect the angle of the mouse before spawning the whip, basically as the click of the mouse happens, so that the animation will suit the direction the player clicked in.

But so far I've had no luck in finding a way to do this. Any ideas?

• Is the problem that you are using different player animation for each direction?

You can have a condition for each.

On mouse click --> spawn whip

etc

[sub event]

is anglediff(angle(player,mouse),270) less than 22.5

-> set player animation to UpWhip

is anglediff(angle(player,mouse),0) less than 22.5

-> set player animation to RightWhip

is anglediff(angle(player,mouse),90) less than 22.5

-> set player animation to downwhip

etc

this condition:

is anglediff(angle(player,mouse),0) less than 22.5

would simply be system> compare two values.. it's basically asking if the angle is within 22.5 degrees of 0.

There would be a way of condensing this to one event with a bit of maths and animations named simply as '0', '1', '2', '3'.. but this is an easier starting point.

• Thanks for the quick response!

Hm, your idea makes sense, but one thing I can't figure out is:

"is anglediff(angle(player,mouse),270) less than 22.5"

^^^

When I use something similar to this, it tells me that "angle" needs four parameters and I only have two... to be honest I don't understand why.

Another potential problem may be that from there, the whip will spawn too early, since the beginning of each animation is sort of a wind up so to speak.

• ## Try Construct 3

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

Construct 3 users don't see these ads
• sorry, I simplified the expression for ease of reading

it's meant to be

angle(player.x,player.y,mouse.x,mouse.y)

If you type in "angle(" a little box should appear telling you what parameters it needs, same goes for all expressions.

• 4 posts