Files
uni/year3/semester1/CT3536: Games Programming/labs/Weeks 4-8/Asteroids/Assets/SpeedLimiter.cs
2024-03-09 19:25:59 +00:00

18 lines
435 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpeedLimiter : MonoBehaviour {
// inspector settings
public Rigidbody rigid;
public float speedLimit = 5f;
//
// Update is called once per frame
void FixedUpdate () {
float spd = rigid.velocity.magnitude;
if (spd > speedLimit)
rigid.velocity *= speedLimit / spd;
}
}