- Home /
rotate animation
Hi,
I am unsure of the best way to rotate an animation. I just want to press the left key and have the animated model face left. Currenly it moves fine .
I have gameobject (animation) with 3 children which are 2 child objects part of the animation and a camera. If I change the y rotation value of 1 of the animation children it turns and the camera stays put.
//this turns the object left and the camera as well which I dont want.
transform.eulerAngles = new Vector3(0, -90, 0);
//this turns it left but on every frame so it spins around on every left key press.
transform.Rotate(0, -90, 0);
how do i get the model to turn left/right/forward/back when I press an arrow key. I can move the model in thje direction, it just dosnt face the direction it moves.
Answer by hagar · Jun 18, 2012 at 03:50 AM
Ok I solved it. I will place this an answer.
Transform child1; child1=transform.Find("model1:Master_CTRL");
child1.transform.eulerAngles = new Vector3(0, -90, 0); //face left
If I cant do this or there is a better way then let me know and I will delete this post.
Answer by Berenger · Jun 18, 2012 at 02:44 AM
If you want the rotation to be instantaneous, you can use transform.Rotate when the input is pressed (and only then, so it's done once).
If you want it to be animated, you need to rotate over time. You can use coroutines for that. I could write it for you, but I suggest you try yourself first.
Important : If the animation's component is on the highest transform, the one that you want to rotate, you must not play an animation clip that contains keys on the rotation, or it would override your modifications.
I need to rotate a child object. I have the gameobject with the animation and controller script, below this I have 3 children a camera 2 mesh children for the animation named geometry and master with nothing in the inspector apart from x,y,z.
I can get this valu from the child
child1=transform.Find("model1:$$anonymous$$aster_CTRL");
print ("y rotation= " + child1.transform.eulerAngles.y);
Your answer