...Have an Eye Follow the Cursor

Get help using Construct 2

Post » Fri Dec 28, 2012 5:14 am

Hello All,

I'm trying to incorporate this functionality (eyes following the mouse cursor)into my Construct2 game & I'm having trouble.

http://www.riacodes.com/flash/eyes-follow-the-cursor/

The example is in ActionScript3 but the idea is essentially;

angleDegress = Math.atan2(mouseY-eye.y,mouseX-eye.x) * 180 / Math.Pi

Now, in Construct2 there is no atan2 (I believe atan2 is simply angle in C2)but my thinking was I could express it as such:

every tick->eye->set rotation to mouse.Y-eye.Y* 180 / Math.Pi, mouse.X-eye.X* 180 / Math.Pi

...that doesn't work and neither do several similar attempts.
Can someone please tell me what I'm doing wrong?

Thank you in advance.
B
23
S
7
Posts: 79
Reputation: 2,215

Post » Fri Dec 28, 2012 11:38 am

How about this ?
https://www.dropbox.com/s/ktci7yy0gbgos4e/eyes.capx
B
44
S
15
G
9
Posts: 1,096
Reputation: 11,013

Post » Sat Dec 29, 2012 5:39 am

Thanks for going to all the trouble of making a capx. I appreciate it but I cannot view it as I'm still using release 103 and am not in a position to upgrade to 114.

If you could copy/paste a graphic or write it out I'd be very interested in seeing how you solved it.

Thank you for your time.
B
23
S
7
Posts: 79
Reputation: 2,215

Post » Sat Dec 29, 2012 12:40 pm

Hope this helps.


https://www.dropbox.com/s/nwd0oz1iafymwm4/eyes-how-to.jpg

Tried inserting the image in the post but i couldnt.. dont know why.spongehammer2012-12-29 12:49:38
B
44
S
15
G
9
Posts: 1,096
Reputation: 11,013

Post » Sat Dec 29, 2012 4:12 pm

I would advise you to update C2 to the latest version since there's no good reason not to as far as I can tell (r114 is a stable version). It will not break your existing projects, and if you're worried about that you can just make a backup before updating.

Anyways, you can do what you want of course. If you should need atan2 for anything, here's a way to do it in C2:

[quote=Ashley]It's used in the system angle() expression, which as far as I'm aware, is the only purpose for atan2 - calculating the angle between points.

If you really do need atan2 for something else, I'd be interested to know what it is! You can also get an atan2(y, x) anyway by doing angle(0, 0, x, y).[/quote]Nimtrix2012-12-29 16:13:28
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Mon Jul 22, 2013 12:24 pm

Hi. The link is broken, does anyone have another example how this works please?
B
47
S
14
G
5
Posts: 635
Reputation: 8,017

Post » Mon Jul 22, 2013 12:53 pm

@Bl4ckSh33p

depending on how you have your sprites set up, this is fairly simple.

Sprite - set angle toward position - mouse.x,mouse.y
or
Sprite - set angle - angle(eye.x,eye.y,mouse.x,mouse.y)

if you are using two sprites (one for the eye and one for the iris) it gets a bit more difficult.
You could just set the origin point for the iris at the middle of the eye-sprite and use above events, but if you want more realistic eye-movement, being able to go to the center of the eye-sprite, more calculating is needed.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
53
S
16
G
8
Posts: 6,157
Reputation: 19,744

Post » Mon Jul 22, 2013 2:13 pm

Hi, thanks for the hint.

I have 2 eyes and it would be great if both could move around in the "eyecircle". Rotating with angle alone does not move them in the whole circle.
I found this Xeyes site (http://arc.id.au/XEyes.html) but don't know how to add it to Constructor 2 properly. Any help would be very much appreciated.

I need to learn more about math to use angle or sin/cos properly, its way too long since I used this at school.
B
47
S
14
G
5
Posts: 635
Reputation: 8,017

Post » Mon Jul 22, 2013 2:41 pm

Just throwing this out, but in the Ghost Hunter example, the hero rotates to follow the mouse...
B
21
S
3
G
1
Posts: 98
Reputation: 1,864

Post » Mon Jul 22, 2013 2:53 pm

@Bl4ckSh33p


Here you go..

Eyes
B
44
S
15
G
9
Posts: 1,096
Reputation: 11,013

Next

Return to How do I....?

Who is online

Users browsing this forum: BinaryPanda, MarkThomas and 18 guests