[SOLVED] How do I get the angle of the Mouse's movement

Get help using Construct 2

Post » Fri Oct 07, 2016 1:52 pm

Hey y'all,

I recently needed the angle of the mouse's movement in one of my projects.
Essentially, I need the angle in which the user moves the mouse, e.g. for a duration of 0.2 seconds.

My idea to solve this:
I came up with the idea to create global variables which store the Mouse.X and Mouse.Y and get refreshed every 0.2 seconds (let's call them "LastKnownX" and "LastKnownY").
As soon as either of those variables doesn't correspond with the current Mouse's position, the angle of movement is calculated via
Code: Select all
angle(LastKnownX,LastKnownY,Mouse.X,Mouse.Y)


This works okay, isn't very smooth though.

My question now is:
Is there a better (more effective) way of doing this?

Thanks for any help.
_____________________________
.capx of my setup: https://www.dropbox.com/s/8gkhpl7smf2eh36/MouseAngle.capx?dl=1
image of my current setup: http://i.imgur.com/3wtATXJ.png
Last edited by randomly on Sat Oct 08, 2016 2:51 pm, edited 1 time in total.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Fri Oct 07, 2016 8:56 pm

What can be more efficient than calculating the angle of point A to point B? Seems like a fine method to me...
B
45
S
15
G
73
Posts: 2,006
Reputation: 43,394

Post » Fri Oct 07, 2016 10:12 pm

@plinkie

Well that's why I asked.
Because I'm still learning and the angle doesn't seem to be very smooth when the mouse is moving smoothly.
If that's the best solution possible, then I'm fine with that. :)

Well, maybe there is a better solution for the stuff before the angle() stuff...
Last edited by randomly on Fri Oct 07, 2016 11:32 pm, edited 1 time in total.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Fri Oct 07, 2016 10:50 pm

Ya seems pretty good, not entirely sure what you mean by smooth though. I made a capx where you click in two spots and it shows the angle from the first click, seems fine! If you're working out the new co-ords after 0.2 secs timer it should work in a similar way. https://dl.dropboxusercontent.com/u/495 ... seang.capx
B
45
S
15
G
73
Posts: 2,006
Reputation: 43,394

Post » Fri Oct 07, 2016 10:51 pm

I don't know what kind of gameplay you're going for, however, I found out that a simple rotate towards angle instead of set angle makes it look a little smoother.
Image

Good luck with your project :D
B
12
S
8
G
3
Posts: 33
Reputation: 3,483

Post » Fri Oct 07, 2016 10:57 pm

B
33
S
18
G
27
Posts: 2,441
Reputation: 20,346

Post » Fri Oct 07, 2016 11:41 pm

Thanks so much everyone for your responses!

I took a look at @99Instances2Go 's and @plinkie 's capxs. I figured, I'd just add the "rotate to" action to my project, because that looks like the easiest and shortest version to me (I'm a lazy person). Thanks @Brandon12hummer for your suggestion!

This is solved, thanks again!

(I hope I don't disappoint those who created a capx, I opened them and read through it, I just think that it's less work to just optimize my existing project. Thank you anyways for taking the time to deal with my problem. :) I wish there was a thanks button on this forum...)
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091


Return to How do I....?

Who is online

Users browsing this forum: ivanski1983, KTML5 and 6 guests