*
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class Brake : MonoBehaviour {
|
||||
public float _friction = 100;
|
||||
public float _radius = 0.2f;
|
||||
public float _area = 0.2f;
|
||||
public float _max_pressure = 10;
|
||||
public float _bias = 1;
|
||||
private float _threshold = 4.0e-4f;
|
||||
private bool _is_locked;
|
||||
|
||||
public Brake() {
|
||||
|
||||
}
|
||||
|
||||
public Brake (float sliding, float radius, float area, float max_pressure, float bias) {
|
||||
_friction = sliding;
|
||||
_radius = radius;
|
||||
_area = area;
|
||||
_max_pressure = max_pressure * bias;
|
||||
_bias = bias;
|
||||
}
|
||||
|
||||
public float GetTorque(float factor, float rotational_speed) {
|
||||
// `factor' is the fraction of maximum pressure applied.
|
||||
float pressure = factor * _bias * _max_pressure;
|
||||
float normal = pressure * _area;
|
||||
float torque = _friction * normal * _radius;
|
||||
float velocity = _radius * rotational_speed;
|
||||
if(velocity < 0.0f)
|
||||
torque *= -1;
|
||||
|
||||
// See if the brake is locked.
|
||||
if(Mathf.Abs(velocity) < (_threshold * normal)) {
|
||||
_is_locked = true;
|
||||
torque = 0.0f;
|
||||
} else {
|
||||
_is_locked = false;
|
||||
}
|
||||
|
||||
return torque;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user