using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class RigidbodySpeedLimiter : MonoBehaviour { public float maxSpeed = 5f; public float minSpeed = 2f; private Rigidbody _rigidbody; private void Start() { _rigidbody = GetComponent(); } void FixedUpdate() { if (_rigidbody.IsSleeping()) return; float velocity = _rigidbody.velocity.magnitude; Debug.Log(velocity); if (velocity < minSpeed) { _rigidbody.velocity = _rigidbody.velocity.normalized * minSpeed; } else if (velocity > maxSpeed) { _rigidbody.velocity = Vector3.ClampMagnitude(_rigidbody.velocity, maxSpeed); } } }