• 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 tom.coursow · Apr 11, 2014 at 07:40 PM · rotationquaternionaxistank

Tank urret rotation - Need help.

Hi guys,

for 3 three hours I try to rotate a tank turret now... And I only get it to smoothly look to the target. But the problem is how can I fix the Z axis of the turret after looking/slerping to the target?

Here is an example:

alt text

After this phase of rotation I want that the local rotation of the turret gets to the same level as the tank hull again. Can anyone help me please? I tried so many experiments on my own with this stupid tank :D

Here is my latest code experiment:

 // The Important snippet from the Weapon.cs Script
 //
 // Transform weaponHolder = <turret set via inspector>
 // The parent of the turret is the hull.
 
 Vector3 direction = target.transform.position - transform.position;
 Quaternion toRotation = Quaternion.LookRotation(direction);
 Quaternion newRotation = Quaternion.Slerp(weaponHolder.transform.rotation, toRotation, Time.deltaTime * 1.5);
 weaponHolder.rotation = newRotation;
 weaponHolder.localEulerAngles = new Vector3(weaponHolder.localEulerAngles.x,
                                     weaponHolder.localEulerAngles.y,
                                     weaponHolder.parent.localEulerAngles.z);

tank_rotation_bug.jpg (29.4 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Apr 11, 2014 at 08:51 PM

Take a look at my answer here:

http://answers.unity3d.com/questions/562443/turret-slerp-rotation-and-clamping.html

You will need to open up the comments at the bottom of my answer and scroll down. The code is just below the link to a package that demonstrates the script.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

21 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

Related Questions

how can i substract one axis by 180? 2 Answers

Get rotation around (forward) axis ? 1 Answer

Rotation to align between two vectors but with preserved Camera Z axis 0 Answers

Lookat via Single Axis 0 Answers

Rotating an object around 2 axis at the same time 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges