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 Clockwork Fromage · May 15, 2011 at 11:35 PM · rotationvector3lookrotation

comparing an object rotation to a direction vector

i need to compare an object's rotation to a directionvector(gravity for now 0,-9.81,0) and to return the difference between the 2 so that i can apply force accordingly

right now im trying to figure out what should be compared , ive been trying to get a meaningfull vector out of quaternion.lookrotation altough it seems to work only for setting the object rotation and not reading it since the result is in local space and is always the same if the object moves

other than that ive looked at euler angles but cant see how to turn the vector to a rotation with them eighter

this is pretty much where im stuck, i need to figure out the equation and next ill just have to see how to work with the result , im working only on 2d to make that part simpler

thanks for the help

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
1

Answer by Jesse Anders · May 16, 2011 at 05:30 AM

You can't really compare an orientation to a vector in 3-d, but you can use the dot product to determine 'how aligned' two vectors are.

For example, assuming transform.up is up for your object, the dot product of transform.up and Vector3.up will tell you whether the object is more or less up-side-up or up-side-down, and to what degree.

Note that the dot product of transform.up and Vector3.up is simply transform.up.y. (I'm assuming the magnitude of the gravity vector doesn't matter here. Also, I realize your reference vector is pointing in the direction opposite Vector3.up, but that's just a matter of switching signs.)

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 Clockwork Fromage · May 18, 2011 at 03:51 AM 0
Share

so here's what come up with so far , im taking my forward vector and physics.gravity and doing the dot product but the result is always 0 so i guess the gravity vector isnt the right typr of expression , here my bit of code , what do you think ?

var gyro : float; var ward : Vector3;

function Start(){ grav = Physics.gravity;}

function Update () { ward = transform.TransformDirection(Vector3.forward); gyro = Vector3.Dot(ward,grav);}

avatar image Jesse Anders · May 18, 2011 at 04:29 AM 0
Share

Ins$$anonymous$$d of writing 'transform.TransformDirection(Vector3.forward)', you can just use transform.forward. As for the problem you mention, there's no problem with computing the dot product of the forward direction vector and the gravity vector. However, depending on what you need the result for, you may want to normalize the gravity vector first, or just use forward.y if the gravity vector is y-aligned. Also, a result of 0 would suggest that the forward vector is perpendicular to the gravity vector.

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

No one has followed this question yet.

Related Questions

Quaternion.LookRotation and Vector3.SmoothDamp Problems 1 Answer

Slerp to make the right/left side face another object 2 Answers

Need help with rotation 4 Answers

Why LookRotation works, but LookAt doesnt 0 Answers

LookRotation Vector3 is Zero, Yet Slerp Still Rotates? 2 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