Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by stoneproductions · Jan 13, 2015 at 06:22 PM · animation2dmouse positioneyes

teeworlds eyes animation

In the 2d multiplayer shooter game named "Teeworlds" the eyes of the character move on a circle so they always "look" at the mouse position. I want to realise this in my game too but I do not even have a hint how to do this. Could anyone give me a tip or a direction to go?

Kind Regards

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by pwnageman2 · Jan 14, 2015 at 08:27 AM

I would have an image for the pupil (black part) of the eye as a separate object than the white part of the eye. Then in a script attached to the pupil, do something like the following:

1- Store the initial position of the pupil (start the pupil in the center of the eye in the scene):

 // before Start () of pupil script
 Vector3 initialPos;
 
  // in Start () of pupil script
 initialPos = transform.position;

2- Find the direction from the pupil to the mouse by doing something like this:

 // in Update() of pupil script
 Vector2 mousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
 Vector2 pupilPosition = new Vector2(transform.position.x, transform.position.y);
 Vector2 directionToMouse = mousePosition - pupilPosition;

 

3- Clamp this direction Vector so that the pupil won't go outside the radius of the eye:

 // still in Update ()
 float radius = 1f; // put in your eye's radius here. you can try various values.
 Vector2 posToAdd = Vector2.ClampMagnitude (directionToMouse, radius);

4- Add this calculated vector to the initial position of the pupil object:

 // still in Update()
 transform.position = initialPos + new Vector3 (posToAdd.x, posToAdd.y, 0f);


That's it! I haven't tested it, but you should be able to fix any syntax errors as long as you understand what is happening.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image stoneproductions · Jan 14, 2015 at 09:17 AM 0
Share

Thank you, this helped alot! The only thing I had to change was the transform.position to transform.localPosition, otherwise the eyes not move with the character.

avatar image pwnageman2 · Jan 20, 2015 at 07:29 PM 0
Share

Awesome! Please upvote and accept this answer if it helped you

avatar image
0

Answer by Berenger · Jan 14, 2015 at 08:21 AM

Here are some stuff you'll need :

Input.mousePosition, camera.ScreenToWorldPoint, transform.LookAt.

I suggest you parent the eyes to a gameobject at the center of the rotation you want, and manipulate that guy instead of the eyes directly. Keep in mind that there is always many ways to do something, and the best one usually is the one you understand the most.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

2D Animation does not start 1 Answer

2D eyes on 3D character? 2 Answers

Sprite alpha animation stop working in Unity 4.5? 1 Answer

Animation disturbing circular rotation 1 Answer

Custom AsyncOperation to show LoadingImage for slowish XML conversion & email upload method in Unity? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges