- Home /
Model moving from Rotation only?
Hello Unity community, I've run into a very disturbing issue today. I downloaded the Zombie Character pack and a few animations today and I am desperately trying to fix this weird bug. So basically, if you rotate an object in a scene, it should not move (only rotate towards you, duh...) . But when i rotate this Zombie model it starts to move towards the direction its facing with a speed of ~ 0,1/s. I'm sure it has to do something with the rotation and the model itself, because when i comment out the rotation code it does not do it, but the same code does not provoke such a behavior for e.g. a cube.
Another thing is that when i get closer the whole model starts to rotate up to face the main camera, so my second question would be how i can make him rotate only on the x and z axis (note : rigbody fix y rotation does not work for me :S)
Code : Rotation:
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,Quaternion.LookRotation(target.position - myTransform.position),rotationSpeed * Time.deltaTime);
Additional codes used: Character Controller (standard asset), Root Motion Computer, Normal Character Motor
Note: This does also happen when i disable any animations!
Thanks in advance, if you need any more code or details please ask, i want to get rid of this issue as fast as possible.
if the zombie is childed to some other empty parent object, with a different position, that could do this.. make sure the part with the $$anonymous$$eshRenderer is at the top of the hierarchy..
Although the part with the $$anonymous$$eshRenderer (hips) is Children to zombie_hires they are, as far as i can tell in the same position. I tried to drag that part on top of the hierarchy but that only led to the whole zombie to disappear.
Answer by Owen-Reynolds · Nov 08, 2012 at 10:56 PM
This is a new way to get an old problem:
The target rotation is over 3D space. When the camera is far away, you're looking only a little bit up to see it, so not obvious. As you get close, the model is leaning back to do a fully 3D rotate to see you. Fix it by manually making the y values equal, to get a 2D only rotation.
You old code for the target rotation:
... Quaternion.LookRotation(target.position - myTransform.position) ...
Break it up instead, to kill the y (in other words, figure out the "level with you" camera, and look at that):
Vector3 lookDir = target.position - myTransform.position;
lookDir.y = 0;
(in your Slerp): ... Quaternion.LookRotation(lookDir) ...
Thanks that solved everything! Oh the irony, I was so close to solving it myself, ins$$anonymous$$d of setting the y of lookDir to 0 I set it to the player objects y. I don't know why but it seemed logical to me yesterday. Thanks a lot!
You weren't wrong. Temp setting target-Y == my-Y is also a solution. The final lookDirection still comes out as zero.
Very common to try something that would have worked, but have some $$anonymous$$or error elsewhere, so you abandon it.