• 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
1
Question by DJGhostViper · Dec 04, 2016 at 12:43 AM · rotationmovementjointturrettank

Tank turret rotation while tank is moving help

Ok so I'm making a tank and it has a turret that turns to look at the enemy but there are a couple problems I run into. Normally I would put the turret as a child of the tanks body so it can move relative with the body as it moves around but rotating the turret when parented to the body makes the turret resize so it still fits inside the parented body (See TankIncorrect Image). Next I unparented the turret from the body and I got my desired effect it rotates normally but it doesn't stay connected to the body as the body moves away (See TankMoving Image). I've tried using a fixed joint on the turret to keep it on the body but when I want the turret to turn it wont because its fixed to the body. Is there a way to allow the turret to rotate while its using a fixed joint? Thanks any ideas are appreciated!!

tankincorrect.png (127.1 kB)
tankmoving.png (120.3 kB)
Comment
Add comment · Show 3
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 Bryangs · Dec 04, 2016 at 02:48 AM 0
Share

Why the turrent is resized? Can you post your script?

avatar image DJGhostViper · Dec 04, 2016 at 02:51 AM 0
Share

There is no script that goes with this all I did to test that was use the rotate tool at the top left

avatar image Bryangs DJGhostViper · Dec 04, 2016 at 03:48 AM 0
Share

I think i have a quick fix for this. Create a new EmptyGameObject, and make the Turret a child of it. Then make the EmptyGameObject a child of the tank and see if it work.

The problem may be that you used turret as the parent of all the other things inside it, and turret IS a "model". Empty gameobjects doesn't have any mesh, so they can't have their design messed up. As only the parent's scale is changed, not the childs, it should work.

1 Reply

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

Answer by Glurth · Dec 04, 2016 at 04:29 AM

Create a new EmptyGameObject, and make the Turret a child of it. Then make the EmptyGameObject a child of the tank and see if it work.

Close, just think you have the parenting mixed up a bit.

Use an empty game object, with a scale of (1,1,1). You make this empty object the "tank position", and make the tank body a child of the "tank position" object, AND the turret a child of the object.

Now you can move and rotate the "tank position", scale the body, and rotate the turret, all separately.

In general, it gets confusing to have a scaling transform as parent of a transform with a rotation, so to avoid it, I do the above almost every-time I have a scaling transform.

Comment
Add comment · Show 3 · 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 DJGhostViper · Dec 04, 2016 at 03:33 PM 0
Share

Ive figured out how to allow the turret to rotate separately already but it just wont stay connected to the body and move with the body if its not a parent of the body. Ive tried making a gameobject and putting it into the body also but that doesn't work either (See TankIncorrect2). The turret doesn't want to move with the body because its not connected to it and if it was the scale is all messed up even if it is in a empty gameobject. It works fine set up like the image of TankCorrect2 shows without the empty gameobject with the turret but just wont move with the tankbody because it not connected to it. (Please look at the pictures below they should help you see the parenting I tried) Thanks for helping me with this, I don't see a way around this but any feedback is appreciated

@Glurth @Bryangs

tankincorrect2.png (121.0 kB)
tankcorrect2.png (131.7 kB)
avatar image Glurth DJGhostViper · Dec 04, 2016 at 04:51 PM 0
Share

tankcorrect2.png is exactly what I was talking about. Important to remember though: do NOT move or rotate the tank body, rather move & rotate the "tank position" object only. Only SCALE the tank body. (this is because the body's position & rotation, RELATIVE to the "tank position", (localPosition and localRotation) does not change .) Similar, but different; for the turret, do NOT change it's position, (relative to "tank position") just it's rotation. (at least 'till you blow it up!)

This is the big difference between "position" and "localPosition" in a transform: the localPosition is always RELATIVE to the parent. "position" is a combination of the parents position, and the child object's localPosition. Only when an object has no parent are localPosition, ad position the same.

avatar image DJGhostViper · Dec 04, 2016 at 09:28 PM 0
Share

Ive figured it out you also have to put the nav mesh agent on the empty gameobject or it will only move one thing but not the other thanks for helping!!

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

81 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

Related Questions

Rotate tank turret using quaternions 0 Answers

Get rotation of a randomly rotating turret on a moving tank (to Spawn missiles in that direction) 2 Answers

How do I control the rotation of object. 1 Answer

Character Rotation 0 Answers

Struggling to get the rotation the player is moving in. 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