I have an object that rotates at different times and different rotations and I can’t figure out what to add for time to keep it from shuttering using rotate towards. How do I get/measure the time between each new rotation?
Here is a code sample if you still need it:
//calculate target vector
Vector3 vec = (targetGO.transform.position - transform.position).normalized;
//interpolate towards goal
transform.forward = Vector3.Lerp(transform.forward, vec, Time.deltaTime * speed);
where speed defines your rotation speed.
Lerp(a, b, t) is a linear interpolation from a to b with parameter t. If t = 0,
then it returns a, if t = 1
it returns b. If it is between 0<t<1
, then it is linearly in between the two
You should normalize the targetvector, otherwise it will rotate faster is the goal point is far away.
Standard untested disclaimer
Where you have speed I don’t have a constant speed with different forces being applied to the object. That’s what I need to figure out I think.
There is a main object that moves and rotates based on forces applied to it’s RigidBody and a clone of that object that needs to equal that movement. The object clone receives a position and rotation from the main object only. How would I get the maxDegreesDelta that Quaternion.RotateTowards and Vector3.MoveTowards calls for, which would vary in my case?