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 RandomXT · Jan 19, 2013 at 07:13 AM · rotationquaternionturreteulermouse look

Turret on Tank rotating fine until I'm not flat on ground

I have a TANK with a Turret on top, the turret follows my mouse around the screen and it rotates perfectly. And the turret never clips into the tank thanks to x and z being zerod out. When my tank is climbing a hill though the turret goes right through the tank. I think it has something to do with local angles or something but I can't figure it out.

SEE IT HERE - http://dl.dropbox.com/u/24020723/GAME/TANK.html Take the tank onto a hill and see what happens to turret Thanks!

         Plane zeroPlane = new Plane( Vector3.up, Vector3.zero );
         Ray ray = Camera.main.ScreenPointToRay( Input.mousePosition );
         float distance;
         if( zeroPlane.Raycast( ray, out distance ) )
        {
               Vector3 outputPosition = ray.origin + ray.direction* distance;    
               var newRotation = Quaternion.LookRotation(outputPosition-turretRotate.position).eulerAngles;
                 newRotation.x = 0;
                 newRotation.z = 0;
                  turretRotate.rotation = Quaternion.Euler(newRotation);

}

Comment
Add comment · Show 7
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 Imankit · Jan 19, 2013 at 07:20 AM 0
Share

Turret is a child of the tank or not??

avatar image Imankit · Jan 19, 2013 at 07:21 AM 0
Share

It should be the child of the tank

avatar image RandomXT · Jan 19, 2013 at 03:24 PM 0
Share

It is the child of the tank - added link to see it in action - thanks for looking

avatar image FL · Jan 20, 2013 at 12:46 AM 0
Share

A shot: turretRotate.Rotate(0,turretRotate.eulerAngles.y+newRotation.y,0,Space.Self)

avatar image Next Beat Games · Jan 20, 2013 at 01:15 AM 0
Share

i haven't thought about this much but would it make a difference if you set the localRotation ins$$anonymous$$d of rotation

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
-1
Best Answer

Answer by bernardfrancois · Jan 20, 2013 at 09:05 AM

I ran into the same issue when doing a tank with turret before. You'll need to use Transform.localRotation in order to use the local object's up / Y axis in the Quaternion.AngleAxis method:

 Transform turretTransform = transform.Find ("Turret");
 turretTransform.localRotation = Quaternion.AngleAxis (turretAngle, Vector3.up);

Looks obvious, but still took a while to figure out.

Note that you may have to change Vector3.right to Vector3.up or Vector3.forward in this line of code, depending on the axis containing the longest direction (I'd recommend reexporting the object though, as it would make it more intuitive while programming).

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 RandomXT · Jan 20, 2013 at 12:33 PM 0
Share

Sorry I want to make sure I understand, how do I get turretAngle? if you don't $$anonymous$$d can you show example with my variable names? I'm a complete coding noob, thanks so much for your help

avatar image bernardfrancois · Jan 20, 2013 at 09:55 PM 0
Share

turretAngle could be a variable you'd have added to your class, which would contain the angle. For instance when you press certain buttons, you'd increase or decrease this variable.

If you don't understand this, I suggest reading more about the program$$anonymous$$g language you're using, and also reading the documentation on the Input class in the Unity scripting reference.

Good luck with it!

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

12 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

Related Questions

Rotation with a slider 2 Answers

Is there no way to get reliable angles from a rigidbody? 2 Answers

How make child object rotate inverse to its parents rotation ? 1 Answer

apply a modified rotation based on another objects' rotation 1 Answer

Why is Quaternion.Eular only rotating in one direction? [Answered] 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