• 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 husbandofemily · Jun 15, 2013 at 07:02 AM · rotationparentchild

Rotate both parent and child around parent

Hi all, I've searched for this, but having no joy. Apologies if someone's already answered this. I have a gun on an NPC aircraft, with a very long child cylinder pointing where the gun does, and a trigger attached to the end of the cylinder. The trigger detects when the gun is pointing roughly at the right thing, and the gun slerps to point at the target. This works.

alt text

However, when the gun rotates, the child cylinder rotates about itself, instead of the gun.

alt text

I can't use joints, I tried and it messes up the flight of the aircraft. I don't think I can use , as I'm already using slerp. Can anybody think of a way to keep the cylinder effectively pointing out of the barrel? Thanks for any help in advance Ian.

answers1.jpg (161.2 kB)
answers2.jpg (176.3 kB)
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 robertbu · Jun 15, 2013 at 07:26 AM 1
Share

I read your description, but I cannot figure out how you are getting this behavior. I thinks folks are going to need more information before they can give you an answer...any script on the gun and cylinder and perhaps a video of the behavior.

avatar image husbandofemily · Jun 15, 2013 at 07:28 AM 0
Share

Fair point. Just a $$anonymous$$ute, I'll put the scripts up, and look into a video...

avatar image husbandofemily · Jun 15, 2013 at 07:32 AM 0
Share
 #pragma strict
 var colliderScript: bigBoyGunCollider;
 var tgt : Transform;
 var chopper : Transform;
 
 
 function Start () {
     colliderScript = transform.root.Find("gunBase/gunEmpty/gunBarrel/cylinderLook/bigBoyGunCollider").GetComponent(bigBoyGunCollider);
     chopper = GameObject.Find("chopperPhysics").transform;
 
 }
 
 function Update () {
 if(colliderScript.tgt)
     {
         tgt = colliderScript.tgt;
     }
     else tgt = null;
     
 if(tgt)
     {
         var rotation2 = Quaternion.LookRotation(tgt.gameObject.transform.position - transform.position);
         
         transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation( tgt.transform.position - transform.position ),  Time.deltaTime * 2);
         
     }
 
 }
avatar image husbandofemily · Jun 15, 2013 at 07:35 AM 0
Share

tbh there's no point adding the script for the collider/trigger. As you can see above, it just reports when it hits a valid target, and makes "tgt" the target transform. From there the gun slerps to look at the target. Struggling with video, so I'll run the game and get a betternscreenshot of when the gun and red cylinder don't line up properly.

avatar image husbandofemily · Jun 15, 2013 at 07:42 AM 0
Share

O$$anonymous$$, so here's before target acquisition: alt text

and here's once the target has been picked up and put in the tgt variable, and the gun has been slerp'd to look at tgt center:

alt text

The gun is pointing where it should, but the red cylinder is rotating about it's own transform's centre, not the end of the gun.

answers3.jpg (121.3 kB)
avatar image husbandofemily · Jun 15, 2013 at 08:03 AM 0
Share

O$$anonymous$$, apologies for the terrible quality, but a quick vid of what's happening. If you look closely, you can see the gun moves as it should...

Video on YouTube

avatar image husbandofemily · Jun 15, 2013 at 07:55 PM 0
Share

To confuse matters, looking more closely the actual rotation figures of the long cylinder don't change. Is this some type of bug then, anyone?

0 Replies

· Add your reply
  • Sort: 

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

14 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

Related Questions

Make a simple tree 1 Answer

How can I make a First Person Character Controller a child of a moving platform without it affecting the rotation of the Character Controller. 1 Answer

Child ignoring parent rotation? 1 Answer

How can I identify a non-uniform scaled mesh, and fix it? 1 Answer

How to fix Child Object Rotations.? 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