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
1
Question by Lord Simpson · Apr 02, 2011 at 03:49 PM · rotationvector3quaterniondirectionturret

3D nested Turret Prefab Rotation

Hi I have a system where a ship has a turret attached to it, the ship has full 3d movement and the turret is comprised of 2 parts as shown in the Hierarchy image below.

alt text

The base should just rotate via yaw and the head which should use both yaw and pitch [should look like its just pitching since base yaw = head yaw] currently it works perfectly except when the ship rotates about the Z axis [roll] when the turret base and head go out of alignment with the surface they are "attached" to and gain extra roll which doesn't look right.

I'm sure its to do with my rotation code [attached to the "1SML-TwinTurret" object] but I cant seam to work out the correct method to fix it. currently I'm using this.

    Vector3 direction = Vector3.Normalize (target.position - transform.position);
    Vector3 basetarget = new Vector3 (direction.x, 0, direction.z);     
    turretbase.rotation = Quaternion.RotateTowards (turretbase.localRotation, Quaternion.LookRotation (basetarget), turnspeed * Time.deltaTime);
    turrethead.rotation = Quaternion.RotateTowards (turrethead.localRotation, Quaternion.LookRotation (direction), turnspeed * Time.deltaTime);

I'm sure there's a better way to do this but I cant seam to work it out, ideally I want to have both the head and the base's roll the same as the ships and them to rotate at a fixed speed towards its target.

Any help would be appreciated

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

Answer by Lord Simpson · Apr 03, 2011 at 12:38 PM

Ok think ive fixed my own problem again :D

turrethead.rotation = Quaternion.RotateTowards (turrethead.rotation,Quaternion.LookRotation(direction,transform.up), turnspeed * Time.deltaTime);
Vector3 rot = turrethead.localEulerAngles;
rot.x = 0; rot.z = 0;
turretbase.localEulerAngles = rot;

Realised all I had to do to fix the roll problem was use add transform.up to the LookRotation [didn't realise it had that option...]

The base was being problematic but then I realised I could just lock it to the head's rotation and it seams to be passing all my test.

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

No one has followed this question yet.

Related Questions

Quaternion amount/value of rotation? 2 Answers

How can I rotate a tank's turret back to the starting turret position? 2 Answers

Rotate vector3 relative to another vector3 1 Answer

Rotate object based on hit normal + matching camera direction 0 Answers

Get rotation from a vector direction. 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