- Home /
Cannot rotate GameObject from C# Animator attached
I have tried almost every api call that lets you rotate a gameobject, and this thing will NOT rotate via code, using C#.
It has an animator attached that animates rotation, but the rotation animation is not playing when I try to rotate from code (only a position animation is playing).
The gameobject & parents are not static.
Have tried rotation gameobject and parent, neither one will rotate.
Have tried euler angles rotations, quaternion rotations, transform.lookat, no errors but the thing will never rotate from it's original position while playing the position animation (up-down motion animating Y value of position.
I even recorded a youtube video to help explain the problem: [http://youtu.be/qfv0IP0LQU4][1] [1]: http://youtu.be/qfv0IP0LQU4
Why can't I rotate this gameobject from code? Any help much appreciated!!
that object "arrow is rotating in video than what is problem where you want rotation? i can not get your point plz write comment here to get help from me
I think the animator on the arrow was interfering, so putting rotation code into LateUpdate makes the arrow actually rotate now.
Need some help still though, see I'm not doing anything on each frame only calling "transform.lookAt" one time, so update or LateUpdate not the best because I have to check if I should run that line of code every frame. For example (this works finally though!):
void LateUpdate(){ if (shouldLookAtPlayer == true) { transform.LookAt(transform.position); } }
So now I have to set a bool, and then every frame it has to check if that's true or false, then run my line of code. Is there a way to run function "late" without LateUpdate?
For example, something like:
void $$anonymous$$yFunctionThatRunsLate(){ transform.LookAt(transform.position); }
And then I can just call that without running a bool check every frame?
Answer by Selzier · Mar 26, 2015 at 07:37 PM
"If its the animator interfering, putting rotation code into LateUpdate should fix your problem."
Thanks to James at the Unity Forums. I still have a question though, see I'm not doing anything on each frame only calling "transform.lookAt" one time, so update or LateUpdate not the best because I have to check if I should run that line of code every frame. For example (this works finally though!):
void LateUpdate(){ if (shouldLookAtPlayer == true) { transform.LookAt(transform.position); } }
So now I have to set a bool, and then every frame it has to check if that's true or false, then run my line of code. Is there a way to run function "late" without LateUpdate?
For example, something like:
void MyFunctionThatRunsLate(){ transform.LookAt(transform.position); }
And then I can just call that without running a bool check every frame?