Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 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 /
avatar image
0
Question by Tryggvi · Apr 28, 2010 at 10:51 PM · rotationvector3quaternionlookrotation

Need help with rotation

Hi, Im writing a simple tank game, It has a tank with a turret and a cannon attached and a hilly terrain.

The problem is that when the tank is at an angle the script doesnt rotate the turret and the cannon correctly. The turret house should only rotate on Z and the cannon attached on X. I think the problem is that my script doesnt take into account the new angle the tanks is in.
Can anybody help with this problem? Thanks.

The following script controls the turret.

var TargetLoc : Vector3; var targetObject : GameObject; var RotateSpeed = 6.0; function Update () { if(targetObject !=null ) TargetLoc= targetObject.transform.position;

 // Rotate towards target    
 var TankRotation = transform.rotation;
 var targetRotation = Quaternion.LookRotation (TargetLoc - transform.position);
 transform.rotation = Quaternion.Slerp(TankRotation, targetRotation, Time.deltaTime * RotateSpeed);

 transform.localRotation.y = 0;
 transform.localRotation.x = 0;

 var targetRotation2 = Quaternion.LookRotation (TargetLoc - transform.Find("TurretHouse/Cannon").position);
 transform.Find("TurretHouse/Cannon").rotation = Quaternion.Slerp(transform.Find("TurretHouse/Cannon").rotation, targetRotation2, Time.deltaTime * RotateSpeed);

 transform.Find("TurretHouse/Cannon").localRotation.z =0;
 transform.Find("TurretHouse/Cannon").localRotation.y =0;

}

Comment
Add comment · Show 1
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 Tryggvi · Apr 29, 2010 at 04:47 PM 0
Share

I think Ive realized the problem. It has to do with the change in x axis when importing from blender. http://answers.unity3d.com/questions/6635/asset-import-from-3dsmax-rotation-issue

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by e-bonneville · Apr 28, 2010 at 11:08 PM

Have a look at this question, which goes into detail on locking rotation and that kind of thing. It also has a good follow script, just make sure your player is tagged "Player".

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 khalil · Apr 29, 2010 at 12:43 AM

You could also separate the turret as a game object and the tank as another game object and reprogram 2 scripts one for tank and one for turret. And possibly use input functions to control the tank and turret as u see fit.

Comment
Add comment · Show 1 · 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 Tryggvi · Apr 29, 2010 at 09:26 AM 0
Share

The Tank and the turret has its own script. The tank is controled my the keypad, and the turret locks on to a target via mouse. $$anonymous$$aybe I didnt explain my problem correctly. The turret and cannon rotate, on a level surface, correctly. It aims the cannon at its target. But when the tank goes up a hill or is leaning sideways, the aim is of. The turret doesnt rotate correctly. It appears to not rotate enough...

avatar image
0

Answer by Tryggvi · Apr 29, 2010 at 05:06 PM

I think Ive realized the problem. It has to do with the change in x axis when importing from blender. answers.unity3d.com/questions/6635/ Tryggvi 17 mins ago

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 n8 · Jun 10, 2010 at 07:23 PM

just another suggestion, I would make sure that the script is operating in local space not world space. When in local space, the script should ignore the world space rotation of your tank.

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

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

LookRotation Vector3 is Zero, Yet Slerp Still Rotates? 2 Answers

Turret rotation on one axis problems 2 Answers

Quaternion.LookRotation and Vector3.SmoothDamp Problems 1 Answer

Rotating a direction Vector3 by Quaternion 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