x


Child object is not rotating with parent

So I have an enemy that follows the player, with a child object that is initially aligned exactly with the parent, that I want to constantly oscillate back and forth in the parent's forward 180 degree arc.

I have it working, but its using world space no matter what I try. Here's how I'm doing it:

function Update(){

    if(reverse){
       transform.Rotate(-transform.up*Time.deltaTime*30.0, Space.Self);
       if(transform.rotation.eulerAngles.y < 90.0)
         reverse = false;
    }
    else{
       transform.Rotate(transform.up*Time.deltaTime*30.0, Space.Self);
       if(transform.rotation.eulerAngles.y > 270.0)
         reverse = true;
    }

}

I've tried a multitude of combinations, between changing transform.up to transform.parent.up, Space.World, etc., to no avail :(

more ▼

asked Sep 11 '11 at 06:19 PM

PrimeDerektive gravatar image

PrimeDerektive
3.1k 57 64 84

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

1 answer: sort voted first

Sounds like you want to use localRotation, not rotation.

more ▼

answered Sep 11 '11 at 08:52 PM

Waz gravatar image

Waz
6.4k 22 33 70

Ugh, such a noobish mistake! For some reason I kept thinking transform.rotation.eulerAngles would be giving me the local by default, like transform.forward/transform.right, etc... and I was wondering why when I was echoing the eulerAngles my values were completely different than the inspector!

Sep 11 '11 at 11:25 PM PrimeDerektive

So I got it working, had to change my values in the if statements because they are different for local. It works great, it's a particle system parented to an enemy shooting fire back and forth, and its oscillating properly and spraying fire back and forth no matter where the parent object rotates. However, after about 30 seconds of running the game it gets stuck occasionally. A gimbal lock issue, maybe?

Sep 12 '11 at 03:43 PM PrimeDerektive
(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:

x2163
x24
x2

asked: Sep 11 '11 at 06:19 PM

Seen: 1003 times

Last Updated: Sep 12 '11 at 03:43 PM