Hello,
I’m hoping someone could explain this problem I’m having with localRotation.
I’m using following bit of code to get my player model to jump up and rotate at the same time (so it looks like it is running on the roof). This bit works fine.
//Jump Up
transform.localPosition = Vector3.Lerp(endPoint,startPoint, (Time.time - startTime) / duration);
transform.localRotation = Quaternion.Lerp(transform.localRotation, target,Time.deltaTime * smooth);
The model moves up to Y -2 and rotates along it’s local Z axis by 180
The problem is that when I try to get it to drop down, I can’t get the rotation to work (the transform is fine).
//Jump Down
transform.localPosition = Vector3.Lerp(endPoint, startPoint, (Time.time - startTime) / duration);
transform.localRotation = Quaternion.Lerp (transform.localRotation, targetDown,Time.deltaTime * smooth);
It just appears to totally ignore the Z rotation and the other values I enter are off by a lot / don’t relate to the actual values or axis, but when I jump again (back to the roof), the rotation is correct.
Now I realize that when it’s on the roof, the +Z axis will now be pointing in the other direction (towards the screen)as will the +X axis (pointing left instead of right), but that doesn’t seem to explain the faults.
VAR / values used.
startPoint=Vector3 0,-10,0 //Ground position
endPoint=Vector3 0,-2,0//Roof position
target = Quaternion.Euler (0, 0, 180);//Roof rotation
targetDown = Quaternion.Euler (0, 0, 180);//Ground rotation (also tried various other values)
Basically, when I rotate the player 180 on the Z axis, I would expect that if I rotated it back another 180, it would return back to the original rotation, but that’s just doesn’t happening. So am I doing something wrong, as I don’t really understand the different kinds of rotations (never heard of a Quaternion before) and I can’t find anything that explains it from a novice point of view. I’m at artist, not a coder but I’m slowly getting into Unity and it’s always a buzz to get something up and running on the screen.
Any help / pointers would be greatly appreciated as I am at a total loss now.
Thanks,
Mike
