- Home /
LookAt Translation Not Sticking
I took my dampened lookat code from a post, but I'm still having trouble.
I use A/D to let the player rotate my ship along Y. In addition, after I select a target and hit T, the dampened lookat will turn the ship like it's supposed to. But, if I use the A/D rotation after the lookat, it snaps it back to the original rotation. Moving foward does not snap it back and it behaves the same whether or not I use localRotation or rotation. This is all in Update().
Any ideas?
// Y rotation only
if (Input.GetKey (KeyCode.A)) {
shipY -= turnSpeed * Time.deltaTime;
transform.rotation = Quaternion.Euler (0, shipY, 0);
} else if (Input.GetKey (KeyCode.D)) {
shipY += turnSpeed * Time.deltaTime;
transform.rotation = Quaternion.Euler (0, shipY, 0);
}
// Warp
if (Input.GetKey (KeyCode.T)) {
if (warpTarget) {
var neededRotation = Quaternion.LookRotation (warpTarget.transform.position - transform.localPosition);
var interpolatedRotation = Quaternion.Slerp (transform.localRotation, neededRotation, Time.deltaTime * turnSpeed);
transform.localRotation = interpolatedRotation;
shipY = transform.rotation.y; (this line doesn't fix it either)
}
}
Comment
Best Answer
Answer by Rookhaven · Nov 08, 2011 at 09:18 PM
I figured it out. Dang it.
This line:
shipY = transform.rotation.y; (this line doesn't fix it either)
Would be replaced with this:
var angles = transform.eulerAngles;
shipY = angles.y;