Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by itisieric · Apr 13, 2020 at 12:46 AM · quaternionangleboneanglesangleaxis

Angle of bones to read the same as the inspector.

I'm having problems getting the angle to read the same as the inspector. See the two attached pictures. The 2 pictures should show the same angle because they are the same angle, but they show different numbers that don't mach up to what is in the inspector angle for X. thanks in advance for your help.

[1]: /storage/temp/156514-2-pic.jpg

public class HelpMe : MonoBehaviour { public float angle; public Transform getTransform;

 void Update()
 {
     angle = Vector3.Angle(getTransform.position, transform.position);

     Debug.Log(angle);
 }
2-pic.jpg (287.8 kB)
difrent-angles-but-it-should-be-the-same.jpg (289.1 kB)
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 Bunny83 · Apr 14, 2020 at 02:21 AM

Your code doesn't make much sense ^^. You use two world positions and calculate the angle between them. You can only calculate the angle between direction vectors. Positions are actually direction vectors, however they all start at the world origin and you would calculate the angle between them.


If you want to read the current local angle of a transform you could can use getTransform.localEulerAngles which gives you the 3 euler angles you see in the inspector.

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
avatar image
0

Answer by itisieric · Apr 15, 2020 at 01:00 AM

alt text I tried using getTransform.localEuler!Angles and the rotation are inaccurate see firs pic. The Euler angle goes up then back down to the same number even though the angle changed

Then I tried to get the angle of the lower bone (see the code) but the angle kept changing when I moved the upper bone, even though the lower bone did not change the angle. I thought it was because it was not in local space but as you can see in the pic that did not work or else I'm doing it wrong. @Bunny83 Thanks for your patience with me and your help.

alt text

 public Transform getTransform;
 public float angle;
 public float angleLocal;
 public float eulerAngleX;
 //public GameObject getRotation1;

 //public Transform getTransform2;
 //public GameObject getRotation2;
 public Vector3 localDirection;
 public Vector3 direction;

 void Update()
 {
     localDirection = getTransform.localPosition - transform.localPosition;
     angleLocal = Vector3.Angle(Vector3.forward, localDirection); // - 90

     direction = getTransform.position - transform.position;
     angle = (Vector3.Angle(Vector3.forward, direction)); //- 88.482552f

     eulerAngleX = transform.localEulerAngles.x;
 }



euler.jpg (215.3 kB)
firstpic.jpg (379.2 kB)
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

127 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

Related Questions

user input azimuth and elevation angle. Need Urgent Help 0 Answers

reproducing hingejoint.angle 0 Answers

Bone rotation in LateUpdate goes back to normal every frame 2 Answers

Set rotation based on 1,1,1 style vector? How to convert vector3 to quaternion? 1 Answer

Raycast at angles 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