I keep getting this error and I’m at a loss. The object moves and performs perfectly but this error message keeps popping up. Any insights would be much appreciated.
[20:10:28] Look Rotation viewing vector is zero
UnityEngine.Quaternion:LookRotation (UnityEngine.Vector3)
public class RaptorMove : MonoBehaviour
{
public float amplitude = 1.0f; // The distance the object will move on either side of its starting position
public float speed = 1.0f; // The speed at which the object will move
private Vector3 startPos;
private Vector3 previousPos;
void Start()
{
// Store the object's starting position
startPos = transform.position;
previousPos = startPos;
}
void Update()
{
// Calculate a new position based on the object's starting position, the amplitude, and a sine wave
float newX = startPos.x + amplitude * Mathf.Sin(Time.time * speed);
transform.position = new Vector3(newX, transform.position.y, transform.position.z);
//calculate direction
Vector3 direction = transform.position - previousPos;
if(direction.sqrMagnitude == 0f)
{
return;
}
Quaternion rotation = Quaternion.LookRotation(direction);
transform.rotation = rotation;
previousPos = transform.position;
}
}
@Sobewankanobe , it looks like you’re trying to protect against the error with a check that the sqrMagnitude is zero. That’s not sufficient. direction.sqrMagnitude < 0.001f would probably work, but honestly, any direction vector should have a nice beefy numerical value, nothing near 0 length. Use Debug.Log() to see if you’re detecting short directions properly.