- Home /
Object makes random jumps in rotation
![alt text][1]I made this copy rotation script where it takes a desired object and copies its rotation to the object that the script has. It works, but then once I added an influence variable (percentage value that determines how much it copies the rotation) I noticed a problem. It seems like when influence in set somewhere between 0 and 1 then if I rotate the copyObject too far (), the object will make a jump in rotation, and then if I go too far again, then it will make another jump (and so on).
Here is the script
public class RotationConstraintCD : MonoBehaviour {
[SerializeField]
bool freezeX;
[SerializeField]
bool freezeY;
[SerializeField]
bool freezeZ;
[SerializeField]
[Range(0, 1)]
float influence;
float desiredX;
float desiredY;
float desiredZ;
float finalX;
float finalY;
float finalZ;
[SerializeField]
Transform copyTransform;
void Update()
{
if (!freezeX)
{
desiredX = copyTransform.rotation.x;
finalX = (desiredX * influence);
}
if (!freezeY)
{
desiredY = copyTransform.rotation.y;
finalY = (desiredY * influence);
}
if (!freezeZ)
{
desiredZ = copyTransform.rotation.z;
finalZ = (desiredZ * influence);
}
transform.rotation = Quaternion.Euler (new Vector3(finalX, finalY, finalZ));
}
}
Answer by leftshoe18 · Nov 17, 2018 at 05:56 AM
transform.rotation is a quaternion. You're taking quaternion values and creating a vector3 with them. Try using transform.rotation.eulerAngles.x/y/z instead and see if that helps.
Your answer
Follow this Question
Related Questions
How can I multiply the rotation of a mirrored object? 1 Answer
How do I clamp the Z-Axis Rotation for this code? 1 Answer
Problem with Quaternion.Euler() when rotating object 3 Answers
Head and body rotate threshold 1 Answer
Trying to tween the rotation of a cube in x and z and having trouble 2 Answers