how to set maxspeed rigidbody unity code example
Example: how to set maxspeed rigidbody unity
using UnityEngine; using System.Collections; [RequireComponent (typeof (Rigidbody))] public class NewBehaviourScript : MonoBehaviour { public float maxSpeed = 10f; void Update() { // Trying to Limit Speed if(rigidbody.velocity.magnitude > maxSpeed){ rigidbody.velocity = Vector3.ClampMagnitude(rigidbody.velocity, maxSpeed); } } void OnGUI() { GUI.Label(new Rect(20, 20, 200, 200), "rigidbody velocity: " + rigidbody.velocity); } }