- Home /
Copy rotation of targetObject to current object with an influence in the range from 0-1.
public class CopyRotation : MonoBehaviour { [SerializeField] private Transform targetObject;
[SerializeField]
[Range(0, 1)]
private float influence;
private Quaternion startRotation;
private Quaternion targetRotation;
private void Awake()
{
startRotation = transform.rotation;
}
void Update()
{
targetRotation = targetObject.rotation;
transform.rotation = Quaternion.Lerp(startRotation, targetRotation, influence);
}
}I'm having trouble. I have it so that the float influence determines how much the current object copies the rotation of the targetObject. So if influence is set to .5 then it will copy the rotation of the targetObject multiplied by .5, and a value of 1 would be the full amount of rotation (targetObject rotation multiplied by 1), and 0 copies no rotation. This works but I am having a problem where if influence is less than 1 then it changes the allowed range of the rotation from the original -180 to 180 values to -180 times influence to 180 times influence.
I don't know if I'm explaining this well, but basically my problem is that when I want an influence value lower than 1, the current object's rotation can only exist within the range of (-180 times influence, to 180 times influence). So if the influence is set to .5, then the range would be (-180 times .5, to 180 times .5), which is -90 to 90 degrees. This results in undesired jumps in the rotation of the object.