-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vatsal Ambastha
committed
Sep 27, 2020
1 parent
58e944d
commit 15154cd
Showing
28 changed files
with
4,682 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace Adrenak.Tork { | ||
public class AntiRollUnity : VehicleAddOn { | ||
[Serializable] | ||
public class Axle { | ||
public WheelCollider left; | ||
public WheelCollider right; | ||
public float force; | ||
} | ||
|
||
public new Rigidbody rigidbody; | ||
public List<Axle> axles; | ||
|
||
void FixedUpdate() { | ||
foreach(var axle in axles) { | ||
var wsDown = transform.TransformDirection(Vector3.down); | ||
wsDown.Normalize(); | ||
|
||
float travelL = Mathf.Clamp01(axle.left.GetCompressionRatio()) ; | ||
float travelR = Mathf.Clamp01(axle.right.GetCompressionRatio()); | ||
float antiRollForce = (travelL - travelR) * axle.force; | ||
|
||
if (axle.left.isGrounded) | ||
rigidbody.AddForceAtPosition(wsDown * -antiRollForce, axle.left.GetHit().point); | ||
|
||
if (axle.right.isGrounded) | ||
rigidbody.AddForceAtPosition(wsDown * antiRollForce, axle.right.GetHit().point); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
using UnityEngine; | ||
|
||
namespace Adrenak.Tork { | ||
public class DownForceVsSpeed : VehicleAddOn { | ||
using UnityEngine; | ||
|
||
namespace Adrenak.Tork { | ||
public class DownForceVsSpeed : VehicleAddOn { | ||
[Tooltip("The down force based on the speed (KMPH)")] | ||
[SerializeField] AnimationCurve curve = AnimationCurve.Linear(0, 0, 250, 2500); | ||
|
||
[SerializeField] new Rigidbody rigidbody; | ||
|
||
[SerializeField] AnimationCurve curve = AnimationCurve.Linear(0, 0, 250, 2500); | ||
|
||
[SerializeField] new Rigidbody rigidbody; | ||
|
||
void Update() { | ||
var downForce = GetDownForceAtSpeed(rigidbody.velocity.magnitude * 3.6f); | ||
rigidbody.AddForce(-Vector3.up * downForce); | ||
} | ||
|
||
} | ||
|
||
public float GetDownForceAtSpeed(float speed) { | ||
return curve.Evaluate(speed); | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
using UnityEngine; | ||
|
||
namespace Adrenak.Tork { | ||
namespace Adrenak.Tork { | ||
public class MaxSteerAngleVsSpeed : VehicleAddOn { | ||
[Tooltip("The steering angle based on the speed (KMPH)")] | ||
[Tooltip("The steering angle based on the speed (KMPH)")] | ||
[SerializeField] AnimationCurve curve = AnimationCurve.Linear(0, 35, 250, 5); | ||
|
||
[SerializeField] Steering steering; | ||
[SerializeField] new Rigidbody rigidbody; | ||
|
||
void Update() { | ||
steering.range = GetMaxSteerAtSpeed(rigidbody.velocity.magnitude * 3.6f); | ||
void Update() { | ||
steering.range = GetMaxSteerAtSpeed(rigidbody.velocity.magnitude * 3.6f); | ||
} | ||
|
||
public float GetMaxSteerAtSpeed(float speed) { | ||
return curve.Evaluate(speed); | ||
public float GetMaxSteerAtSpeed(float speed) { | ||
return curve.Evaluate(speed); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
using UnityEngine; | ||
|
||
using UnityEngine; | ||
|
||
namespace Adrenak.Tork{ | ||
public class MidAirSteering : VehicleAddOn { | ||
[Header("Mid Air Steer")] | ||
public float midAirSteerTorque = 1500; | ||
public float midAirSteerInput; | ||
public Rigidbody m_Rigidbody; | ||
|
||
public float midAirSteerInput; | ||
public Rigidbody m_Rigidbody; | ||
|
||
void FixedUpdate() { | ||
SteerMidAir(); | ||
} | ||
|
||
} | ||
|
||
void SteerMidAir() { | ||
if (!Mathf.Approximately(midAirSteerInput, 0)) | ||
m_Rigidbody.AddTorque(new Vector3(0, midAirSteerInput * midAirSteerTorque, 0)); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace Adrenak.Tork { | ||
public class AckermannUnity : MonoBehaviour { | ||
[SerializeField] WheelCollider m_FrontRight; | ||
public WheelCollider FrontRightWheel { get { return m_FrontRight; } } | ||
|
||
[SerializeField] WheelCollider m_FrontLeft; | ||
public WheelCollider FrontLeftWheel { get { return m_FrontLeft; } } | ||
|
||
[SerializeField] WheelCollider m_RearRight; | ||
public WheelCollider RearRightWheel { get { return m_RearRight; } } | ||
|
||
[SerializeField] WheelCollider m_RearLeft; | ||
public WheelCollider RearLeftWheel { get { return m_RearLeft; } } | ||
|
||
public float angle; | ||
|
||
public float AxleSeparation { | ||
get { return (m_FrontLeft.transform.position - m_RearLeft.transform.position).magnitude; } | ||
} | ||
|
||
public float AxleWidth { | ||
get { return (m_FrontLeft.transform.position - m_FrontRight.transform.position).magnitude; } | ||
} | ||
|
||
public float FrontRightRadius { | ||
get { return AxleSeparation / Mathf.Sin(Mathf.Abs(m_FrontRight.steerAngle)); } | ||
} | ||
|
||
public float FrontLeftRadius { | ||
get { return AxleSeparation / Mathf.Sin(Mathf.Abs(m_FrontLeft.steerAngle)); } | ||
} | ||
|
||
void Update() { | ||
var farAngle = AckermannUtils.GetSecondaryAngle(angle, AxleSeparation, AxleWidth); | ||
|
||
// The rear wheels are always at 0 steer in Ackermann | ||
m_RearLeft.steerAngle = m_RearRight.steerAngle = 0; | ||
|
||
if (Mathf.Approximately(angle, 0)) | ||
m_FrontRight.steerAngle = m_FrontLeft.steerAngle = 0; | ||
|
||
m_FrontLeft.steerAngle = angle; | ||
m_FrontRight.steerAngle = farAngle; | ||
} | ||
|
||
public Vector3 GetPivot() { | ||
if (angle > 0) | ||
return m_RearRight.transform.position + CurrentRadii[0] * m_RearRight.transform.right; | ||
else | ||
return m_RearLeft.transform.position - CurrentRadii[0] * m_RearLeft.transform.right; | ||
} | ||
|
||
public float[] CurrentRadii { | ||
get { return AckermannUtils.GetRadii(angle, AxleSeparation, AxleWidth); } | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using UnityEngine; | ||
|
||
namespace Adrenak.Tork { | ||
public class BrakesUnity : MonoBehaviour { | ||
public AckermannUnity ackermann; | ||
|
||
[Tooltip("The maximum braking torque that can be applied")] | ||
[SerializeField] float maxTorque = 5000; | ||
|
||
[Tooltip("Multiplier to the maxTorque [0..1]")] | ||
public float value; | ||
|
||
void FixedUpdate() { | ||
value = Mathf.Clamp01(value); | ||
|
||
float fs, fp, rs, rp; | ||
|
||
// If we have Ackerman steering, we apply torque based on the steering radius of each wheel | ||
var radii = AckermannUtils.GetRadii(ackermann.angle, ackermann.AxleSeparation, ackermann.AxleWidth); | ||
var total = radii[0] + radii[1] + radii[2] + radii[3]; | ||
fp = radii[0] / total; | ||
fs = radii[1] / total; | ||
rp = radii[2] / total; | ||
rs = radii[3] / total; | ||
|
||
if (ackermann.angle > 0) { | ||
ackermann.FrontRightWheel.brakeTorque = value * maxTorque * fp; | ||
ackermann.FrontLeftWheel.brakeTorque = value * maxTorque * fs; | ||
ackermann.RearRightWheel.brakeTorque = value * maxTorque * rp; | ||
ackermann.RearLeftWheel.brakeTorque = value * maxTorque * rs; | ||
} | ||
else { | ||
ackermann.FrontLeftWheel.brakeTorque = value * maxTorque * fp; | ||
ackermann.FrontRightWheel.brakeTorque = value * maxTorque * fs; | ||
ackermann.RearLeftWheel.brakeTorque = value * maxTorque * rp; | ||
ackermann.RearRightWheel.brakeTorque = value * maxTorque * rs; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.