*
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class DriveShaft : MonoBehaviour
|
||||
{
|
||||
public Transform endpoint0;
|
||||
public Transform endpoint1;
|
||||
|
||||
float inv_inertia;
|
||||
|
||||
public float Inv_inertia {
|
||||
get {
|
||||
return inv_inertia;
|
||||
}
|
||||
set {
|
||||
inv_inertia = value;
|
||||
}
|
||||
}
|
||||
|
||||
float ang_velocity;
|
||||
float angle;
|
||||
|
||||
public float Angle{
|
||||
get{return angle;}
|
||||
}
|
||||
|
||||
public float AngularVelocity{
|
||||
get{return ang_velocity;}
|
||||
set {
|
||||
ang_velocity = value;
|
||||
}
|
||||
}
|
||||
|
||||
public DriveShaft() {
|
||||
inv_inertia = 1;
|
||||
ang_velocity = 0;
|
||||
angle = 0;
|
||||
}
|
||||
|
||||
// amount of momentum to reach angular velocity
|
||||
public float GetMomentum(float angvel)
|
||||
{
|
||||
|
||||
return (angvel - ang_velocity) / inv_inertia;
|
||||
}
|
||||
|
||||
// update angular velocity
|
||||
public void ApplyMomentum(float momentum)
|
||||
{
|
||||
ang_velocity += inv_inertia * momentum;
|
||||
}
|
||||
|
||||
// update angle
|
||||
public void Integrate(float dt){
|
||||
angle += ang_velocity * dt;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user