Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity control velocity on rigidbody

[SerializeField] private Rigidbody rb;
[SerializeField] private float rbMaxSpeed;
[SerializeField] private float rbMag;

private void FixedUpdate()
{
	rbMag = rb.velocity.magnitude; // Total xyz magnitude
    if (rb.velocity.magnitude > rbMaxSpeed)
    {
    	rb.velocity = Vector3.ClampMagnitude((Vector3)rb.velocity,rbMaxSpeed);
    }
}
 
PREVIOUS NEXT
Tagged: #unity #control #velocity #rigidbody
ADD COMMENT
Topic
Name
5+6 =