- Home /
Same rotation script affecting different parts of model in different ways.
I am trying to design a game, obviously, but at the moment I am trying to compile various scripts instead of working toward a finished product.
I ran into a problem on a generic mech-type model I created in Blender. Using Unity's generic MouseLook.cs script, I wanted to be able to rotate the just the cockpit of the mech. However, when run, the mouse will have no effect on the cockpit's rotation until about 10 seconds after starting.
When the same script is attached to the entire mech, and not just the cockpit, the mech will rotate immediately after starting.
Does anyone know the cause and/or workaround for this issue? Thanks
Answer by hvilela · Oct 07, 2012 at 03:31 AM
it's weird. The unique cause that comes to my mind is that your model has a 10s animation with keyframes in the same position/rotation, preventing his movement by code. As long all animations are defined to "play automatically" by default it would explain this behavior.
Could be this your problem?
That is indeed a solution. Even though there was no animation, I did export the model with a 'default take' that was set as the animation in the inspector. Once I set the animation to 'none', or disabled 'play automatically' as you said, the cockpit rotated perfectly right after running. Thanks!
Answer by K4g3 · Oct 07, 2012 at 04:01 AM
I found another solution. I created an empty GameObject named CockpitControl, and simply put it between the mech and the cockpit. (Mech is the parent of CockpitControl, which is the parent of Cockpit). Then I attached the MouseLook.cs script to this gameobject instead of the cockpit. For some reason, this hierarchy change seems to have fixed the issue. The animation may still have something to do with it.
It will solve the problem cause your new game object has no keyframes associated to it. The problem of this solution is that you will loose the prefab link.