#Unity rotation lerp with isKinematic

1 messages · Page 1 of 1 (latest)

fast yoke
#

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!

safe wind
#

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

fast yoke
#

I'm not sure if i can make a coroutine fire in fixed update

safe wind
#

There's WaitForFixedUpdate

frozen pecan
fast yoke
#

Trying random rn

safe wind
#

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

fast yoke
#

So random did not work, BUT

#

the values did change

#

the debug.Log values of the rotation

safe wind
frozen pecan
#

So, the logs showed a change, but you saw no visible change?

fast yoke
#

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

safe wind
#

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

fast yoke
#

just so im using it correctly

#

in my while loop, I would yield return new WaitForFixedUpdate();

#

instead of yield return null

#

correct?

safe wind
#

Yeah

fast yoke
#

It works now, thanks

safe wind
#

Oh nice