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 phyzix101 · Oct 19, 2021 at 01:50 PM · angles

Trying to get separate x and y angles for eye look using blend shapes

Hello!

I've been doing pretty well muddling my way though coding, but I can't seem to figure this out.

I want to use blendshapes for eye look, there are 4 for each eye, one for each direction. I'm trying to get separate X and Y values, with negative values for left and down. I thought I had figured it out with the code below, but the numbers I'm getting back make no sense.

 Vector3 relativePosition = lookTarget.position - blendshapeEyeMesh.transform.position;
 Quaternion rotation = Quaternion.LookRotation(relativePosition);
 Quaternion current = transform.localRotation;
 
 float eyeLookX = rotation.eulerAngles.x - transform.localRotation.eulerAngles.x;
 float eyeLookY = rotation.eulerAngles.y - transform.localRotation.eulerAngles.y;
 
 //take x and y values, divide by the max value and discard values larger than one
 
 //set appropriate blend shapes based on positive or negative value 

Is there a function I can use to get a float for the angle for Y and X separately? Or will I have to do something more complicated?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by phyzix101 · Nov 02, 2021 at 10:07 AM

Wow, silly me. Not sure why I thought to use localRotation!

 Vector3 relativePosition = lookTarget.position - blendshapeEyeMesh.transform.position;
 Quaternion rotation = Quaternion.LookRotation(relativePosition);
 Quaternion current = transform.rotation;
 
 float eyeLookX = rotation.eulerAngles.x - current.eulerAngles.x;
 float eyeLookY = rotation.eulerAngles.y - current.eulerAngles.y;

That is getting me numbers closer to what I want. All I need to do now is to make the logic to figure out which number to add/subtract from which, so I don't get small numbers subtracting from 360.

Edit: On looking close the numbers were still a bit odd. So then I found FromToRotation! That worked great, and the logic to do the directions was pretty simple as well. It even works if the character is not upright! Which I thought might involve a lot of code to work out.

 Quaternion lookDirection = Quaternion.FromToRotation(relativePosition, blendshapeEyeMesh.transform.forward);
 float eyeLookX = lookDirection.eulerAngles.x;
 float eyeLookY = lookDirection.eulerAngles.y;
 if (eyeLookX > 180)
 {
         float x = +Mathf.Clamp((360 - eyeLookX) / 45 * 100, 0, 100);
         blendshapeEyeMesh.SetBlendShapeWeight(leftEyeUpID, x);
         blendshapeEyeMesh.SetBlendShapeWeight(rightEyeUpID, x);
 }
 else
 {
         float x = Mathf.Clamp(eyeLookX / 45 * 100, 0, 100);
         blendshapeEyeMesh.SetBlendShapeWeight(leftEyeDownID, x);
         blendshapeEyeMesh.SetBlendShapeWeight(rightEyeDownID, x);
 }
 if (eyeLookY > 180)
 {
     float x = Mathf.Clamp((360 - eyeLookY) / 45 * 100, 0, 100);
         blendshapeEyeMesh.SetBlendShapeWeight(leftEyeRightID, x);
         blendshapeEyeMesh.SetBlendShapeWeight(rightEyeRightID, x);
 }
 else 
 {
     float x = Mathf.Clamp(eyeLookY / 45 * 100, 0, 100);
         blendshapeEyeMesh.SetBlendShapeWeight(leftEyeLeftID, x);
         blendshapeEyeMesh.SetBlendShapeWeight(rightEyeLeftID, x);
 }

I'll probably have to zero out the opposite directions as well, but I think I will have to make a function to control eyelids along with the eyes and add that in there. I'd be interested in knowing if there is anything else I could do better here.

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

128 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Change a property based on angle? 1 Answer

Brand new to Unity, trying to grasp some basic stuff related to cameras and angles 1 Answer

Calculating angles to a target and turning towards it 1 Answer

Why is rotation locking to an axis? 3 Answers

2D Ball Bouncing Angle Problem (Without Rigidbody) 0 Answers


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