- Home /
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.
However, when the gun rotates, the child cylinder rotates about itself, instead of the gun.
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.
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.
Fair point. Just a $$anonymous$$ute, I'll put the scripts up, and look into a video...
#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);
}
}
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.
O$$anonymous$$, so here's before target acquisition:
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:
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.
Your answer
Follow this Question
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