...Have an Eye Follow the Cursor

0 favourites
From the Asset Store
Mouse cursor is something that the player controls and sees all the time, that's why it is so important to make it cool!
  • Hello All,

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

    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.

  • How about this ?

    dropbox.com/s/ktci7yy0gbgos4e/eyes.capx

  • 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.

  • Hope this helps.

    dropbox.com/s/nwd0oz1iafymwm4/eyes-how-to.jpg

    Tried inserting the image in the post but i couldnt.. dont know why.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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:

    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).edited><editID>Nimtrix</editID><editDate>2012-12-29 16:13:28</editDate></edited>

  • Hi. The link is broken, does anyone have another example how this works please?

  • 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.

  • 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. <img src="smileys/smiley9.gif" border="0" align="middle" />

  • Just throwing this out, but in the Ghost Hunter example, the hero rotates to follow the mouse...

  • Bl4ckSh33p

    Here you go..

    Eyes

  • Thats it! And so simple, thank you very much spongehammer. :)

    I thought I have to copy all the things from the xeyes site to make it work but one line is enough.

    I figured out how to ratate towards mouse klkitchens but I wanted them to rotate inside the eyes (radius).

    The solution of spongehammer was:

    Sprite | Rotate 10 degrees toward (Mouse.x, Mouse.y)

  • <img src="smileys/smiley1.gif" border="0" align="middle" /> You're welcome.

  • Hi Bl4ckSh33p

    Sorry to reopen this thread but I've this same issue and I tried to use the rotate toward action but the eyes only rotate on its own axis. Did you change the image point position too? Could you give some more details? Thanks in advance.

    Edited:

  • Hi Bl4ckSh33p

    Sorry to reopen this thread but I've this same issue and I tried to use the rotate toward action but the eyes only rotate on its own axis. Did you change the image point position too? Could you give some more details? Thanks in advance.

    Out of interest - why did you delete your previous post here and then re-add it? You could have just edited it using the 'pencil' icon.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)