#Unity rotation lerp with isKinematic
1 messages · Page 1 of 1 (latest)
here
I realized Im mixing radians and degrees
Im going to fix that issue first hopefully it will help
Ill try the random rotation after!
You are also simulating angular drag by multiplying with 0.95 every rendered frame. It's probably happening way faster than doing it in FixedUpdate
Agreed, I can add a ticker for that
I'm not sure if i can make a coroutine fire in fixed update
There's WaitForFixedUpdate
I legit did not know that existed. Good to add to the toolbox
Trying random rn
I would do the whole thing with WaitForFixedUpdate and do the moving with rb.MovePosition and rotating with rb.MoveRotation, both of those will respect your rb's interpolation
So random did not work, BUT
the values did change
the debug.Log values of the rotation
That was just to check if the issue is here or if something changes the rotation afterwawrds
So, the logs showed a change, but you saw no visible change?
yes
logs show change, but player does not rotate at all
I'm lerping over a period of 2 seconds btw
so should be plenty of time
IEnumerator LerpToPosition(ulong networkId, Rigidbody rb, Vector3 startPos, Vector3 endPos, float duration)
{
float t = 0f;
var angularVelocity = rb.angularVelocity;
var rbTransform = rb.transform;
//convert the angular velocity from radians to degrees
angularVelocity *= Mathf.Rad2Deg;
Debug.Log(angularVelocity);
//disable the rigidbody's physics while lerping
rb.isKinematic = true;
while (t < 1f)
{
//while lerping, make sure the player is not moving
rb.velocity = Vector3.zero;
Debug.Log(rb.rotation.eulerAngles);
//simulate the player's angular velocity
// rb.MoveRotation(Quaternion.Euler(rbTransform.rotation.eulerAngles + angularVelocity * Time.deltaTime));
rb.rotation = UnityEngine.Random.rotation;
Debug.Log(rb.rotation.eulerAngles);
//simulate the angular drag
angularVelocity *= 0.95f;
t += Time.deltaTime / duration;
rbTransform.position = Vector3.Lerp(startPos, endPos, t);
yield return null;
}
rb.isKinematic = false;
lerpingNetworkObjects.Remove(networkId);
}
this is my code rn btw
Debug.Log(rb.rotation.eulerAngles); indeed shows a random rotation
Ill try this out
Remember to use Time.fixedDeltaTime instead of deltaTime then
Not sure if Time.deltaTime turns into fixedDeltaTime if you use it in a coroutine with waitforfixedupdate
just so im using it correctly
in my while loop, I would yield return new WaitForFixedUpdate();
instead of yield return null
correct?
Yeah
It works now, thanks
Oh nice