ソースコード
public float desiredSpeed = 5f; // 一定に保ちたい速度 private Rigidbody2D rb; private void Start() { rb = GetComponent<Rigidbody2D>(); } private void FixedUpdate() { Vector2 velocity = rb.velocity; float currentSpeed = velocity.magnitude; if (currentSpeed != desiredSpeed) { // 速度を一定に調整する velocity = velocity.normalized * desiredSpeed; rb.velocity = velocity; } }