Detect Angle of Mouse?

Get help using Construct 2

Post » Mon Oct 15, 2012 5:05 am

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?
B
16
S
2
G
1
Posts: 156
Reputation: 2,112

Post » Mon Oct 15, 2012 5:22 am

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.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Mon Oct 15, 2012 7:35 am

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.
B
16
S
2
G
1
Posts: 156
Reputation: 2,112

Post » Mon Oct 15, 2012 7:51 am

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.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683


Return to How do I....?

Who is online

Users browsing this forum: Callan S, gamecorpstudio, getplay, Kagubro and 16 guests