Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by nintendoeats · Aug 18, 2017 at 03:27 PM · quaternionspaths

Giving Vertices a Rotation

I have paths, each of which contains a list of vertices. At present they are being used for turrets that can move along the path. In order for them to work correctly they need to not only get their current position from a point along the path, but also their rotation.

Simply setting the turret's forward axis to be towards the next vertex is insufficient because that does not create a distinction between (for example) a circular path on a wall and a circular path around an object. I therefore need to calculate a rotation for which the forward axis points towards the next vertex and the up axis points towards something that I can specify. My intention is to store an "up" rotation for each vertex and lerp between them when the turret is between two vertices.

I have been beating my head against this problem for a week. First I used quaternions and couldn't make that work, then switched to a system that simply specified a float "rotation angle" which would be applied around the forward axis after creating a quaternion facing the next vertex. This can be made to work in a rather clunky way, but then once the path moves in world space (for example if the path sits on an asteroid or is mounted on a ship) it all breaks completely. I know there is a solution involving quaternions, but either I have missed it or it is beyond me, and I would appreciate any assistance.

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
Best Answer

Answer by nintendoeats · Aug 18, 2017 at 09:33 PM

Agh! I did it! I literally had to try 15 different things over the course of at least a week, but I did it!

 Vector2 lookingAdjustment = 
         Vector2.Lerp (vertices [lowerVertex].normal, vertices[upperVertex].normal, requestedPointBetweenBoundingPoints).normalized;
         Quaternion finalRotation = Quaternion.identity;
         finalRotation.SetLookRotation(getFacingVectorFromVertex(lowerVertex).normalized,(Vector3) lookingAdjustment);
 
         return finalRotation;

PathVertex.normal is a Vector2 that is constrained to magnitude 1. This function produces the LOCAL rotation, as the name says. A world-relative rotation is then created like this:

 turret.transform.rotation = path.transform.rotation * path.GetLocalNormalOfPathAtPoint (pathPosition);

It just took a few more hours of doing something else and I FINALLY got it. I hope this is useful to somebody else.

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

111 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

Related Questions

How do I aim a tank turret at a point? 0 Answers

Rotation Issues with compass markers not positioned correctly 0 Answers

Can someone please help me out? thank you in advance! 0 Answers

VR Challenge: Rotation issue when holding object with both hand controllers vertically 2 Answers

I need to get a rigid body object to slowly return to a set position and rotation in the world after a collision. 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