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 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)
Show more comments

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.

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

Delay child objects rotation 0 Answers

Changing child's rotation changes parent's position 0 Answers

Parent-independent rotation 2 Answers

how do I get Parent rotation on Child,how do I use a parents rotation in a child? 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