I’m currently trying to make almost a snake like simulation where a number of cubes are following each other with slight delays. Everything was working as well as the mimicking of the Z rotation of the target causing a spiral until I added transform.LookAt(target). Now the subsequent blocks do not turn in z axis no matter what the target does. here is a bit of the code, excuse the huge mess. ![]()
Quaternion currentRotation = transform.rotation;
Quaternion targetRotationWithoutY = Quaternion.Euler(currentRotation.eulerAngles.x, targetRotation.eulerAngles.y, targetRotation.eulerAngles.z);
Quaternion targetRotationWithoutYZ = Quaternion.Euler(targetRotationWithoutY.eulerAngles.x, 0f, 0f);
desiredRotation = Quaternion.Lerp(currentRotation, targetRotationWithoutYZ, rotationSpeed * Time.deltaTime);
//this makes the objects rotate in the z axis
float desiredZRotation = Mathf.LerpAngle(currentRotation.eulerAngles.z, targetRotationWithoutY.eulerAngles.z, spiralSpeed * Time.deltaTime);
desiredRotation.eulerAngles = new Vector3(desiredRotation.eulerAngles.x, desiredRotation.eulerAngles.y, desiredZRotation);
transform.rotation = desiredRotation;
// Look at the target
transform.LookAt(target.transform.position);
}
I’ve messed with the spiral speed but that doesn’t make a difference.