//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);
//Drecrese Rigidbody Speed
[SerializeField] private Rigidbody rb;
void FixedUpdate() {
//Decrease speed
rb.velocity -= rb.velocity * 0.1f;
}
//speed of rigidbody in m/s
float speed = rigidbody.velocity.magnitude;
[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);