//Set Velocity to a certain speed
[SerializeField] private float maxSpeed = 10;
[SerializeField] private Rigidbody rb;
void FixedUpdate() {
if(rb.velocity.magnitude > maxSpeed) {
rb.velocity = rb.velocity.normalized * maxSpeed;
}
}
Vector3 velocity = new Vector3(10f/*x*/, 10f/*y*/, 10f/*z*/);
GetComponent<Rigidbody>().velocity = velocity;
//for rigidbody2D
GetComponent<Rigidbody2D>().velocity =new Vector2(40,0);
[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);
}
}
rb.velocity = new Vector3(0, 10, 0);