x


Child versus Parent rotations

I am working on an animation that has main object animated along a path. That comes in just fine and is working well. The Main object has a child that I have put the following script on...

// Smoothly tilts a transform towards a target rotation.

var smooth = 2.0;

var tiltAngle = 30.0;

var myParent : Transform;

function Update () {

var tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;

var target = Quaternion.Euler (0, 0, tiltAroundZ);

// Dampen towards the target rotation
transform.rotation = Quaternion.Slerp(transform.rotation, target,Time.deltaTime * smooth);

}

The issue is that now my child object ignores that it is the child of the Main animated object. At least rotationally.

How can I get my child object to still behave as a child, while controlling the local rotational z roll of the object with my script?

more ▼

asked Dec 09 '10 at 08:46 PM

Michael Neely gravatar image

Michael Neely
59 2 2 9

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first
more ▼

answered Dec 09 '10 at 09:21 PM

yoyo gravatar image

yoyo
6.5k 25 39 84

(comments are locked)
10|3000 characters needed characters left

You are setting the rotation of the transform (which is the global rotation) and not localRotation. Change your code to transform.localRotation and see if that is what you want.

more ▼

answered Dec 09 '10 at 09:21 PM

The_r0nin gravatar image

The_r0nin
1.4k 10 14 30

(comments are locked)
10|3000 characters needed characters left

After a few great suggestions, adding this to the beginning of my Update function keeps things oriented properly. Not completely certain why, but this is better.

transform..rotation = Quaternion.Euler(lockPos, transform.rotation.eulerAngles.y,transform.rotation.eulerAngles.x);
more ▼

answered Dec 11 '10 at 12:59 PM

Michael Neely gravatar image

Michael Neely
59 2 2 9

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2245
x460
x439
x427
x25

asked: Dec 09 '10 at 08:46 PM

Seen: 1069 times

Last Updated: Dec 09 '10 at 09:00 PM