MirrorNetworking / Mirror

#1 Open Source Unity Networking Library
https://mirror-networking.com
MIT License
5.26k stars 777 forks source link

feat(NetworkTranformBase): Provide velocity and angular velocity #3909

Open MrGadget1024 opened 1 month ago

MrGadget1024 commented 1 month ago

Usage case:

void OnVelRotChanged(Vector3 newVelocity, Vector3 newRotation)
{
    animVelocity = -MathF.Round(transform.InverseTransformDirection(newVelocity).z / moveSpeedMultiplier, 1);
    animRotation = -MathF.Round(newRotation.y / maxTurnSpeed, 1);

    if (animator)
    {
        animator.SetFloat("Forward", MathF.Round(Mathf.MoveTowards(animator.GetFloat("Forward"), animVelocity, moveSpeedMultiplier * Time.deltaTime), 1));
        animator.SetFloat("Turn", MathF.Round(Mathf.MoveTowards(animator.GetFloat("Turn"), animRotation, maxTurnSpeed * Time.deltaTime), 1));
    }
}

image