I am trying to use lerp and slerp within an update function however I keep getting lost frames every x seconds and stuttering.
public Transform rcsSpace;
public Vector3 plannedPos;
public Quaternion plannedRot;
public void Update()
{
rcsSpace.localPosition = Vector3.LerpUnclamped(rcsSpace.localPosition, plannedPos, 1);
rcsSpace.localRotation = Quaternion.SlerpUnclamped(rcsSpace.localRotation, plannedRot,
1).normalized;
}
You need to use Time.deltaTime
multiplying a speed value for the time amount not 1, 1 will make it jump to the plannedPos/plannedRot.
Example
public Transform rcsSpace;
public Vector3 plannedPos;
public Quaternion plannedRot;
private float _speed = 10f;
public void Update()
{
float time = Time.deltaTime * _speed;
rcsSpace.localPosition = Vector3.LerpUnclamped(rcsSpace.localPosition, plannedPos, time);
rcsSpace.localRotation = Quaternion.SlerpUnclamped(rcsSpace.localRotation, plannedRot, time).normalized;
}
PS: Time.deltaTime
is the amount of time passed since the last frame.
This issue was caused by the objects parent being a rigidbody and thus unity physics conflicts when attempting to change the position and rotation of the rigidbody.