-
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.
Refactor Motor.cs and move artificial constraints into separate classes
- Loading branch information
Vatsal Ambastha
committed
Apr 18, 2020
1 parent
006a8cb
commit 9143c40
Showing
13 changed files
with
155 additions
and
46 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace Adrenak.Tork { | ||
public class DownForceVsSpeed : MonoBehaviour { | ||
[Tooltip("The down force based on the speed (KMPH)")] | ||
[SerializeField] AnimationCurve curve = AnimationCurve.Linear(0, 0, 250, 2500); | ||
|
||
Aerodynamics m_Aerodynamics; | ||
new Rigidbody rigidbody; | ||
|
||
void Update() { | ||
m_Aerodynamics.downForce = GetDownForceAtSpeed(rigidbody.velocity.magnitude); | ||
} | ||
|
||
public float GetDownForceAtSpeed(float speed) { | ||
return curve.Evaluate(speed); | ||
} | ||
} | ||
} | ||
|
11 changes: 11 additions & 0 deletions
11
Assets/Adrenak.Tork/Runtime/Decorator/DownForceVsSpeed.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
Assets/Adrenak.Tork/Runtime/Decorator/MaxSteerAngleVsSpeedConstraint.cs
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,21 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace Adrenak.Tork { | ||
public class MaxSteerAngleVsSpeedConstraint : MonoBehaviour { | ||
[Tooltip("The steering angle based on the speed (KMPH)")] | ||
[SerializeField] AnimationCurve curve = AnimationCurve.Linear(0, 35, 250, 5); | ||
|
||
Steering steering; | ||
new Rigidbody rigidbody; | ||
|
||
void Update() { | ||
steering.range = GetMaxSteerAtSpeed(rigidbody.velocity.magnitude); | ||
} | ||
|
||
public float GetMaxSteerAtSpeed(float speed) { | ||
return curve.Evaluate(speed); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Adrenak.Tork/Runtime/Decorator/MaxSteerAngleVsSpeedConstraint.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
Assets/Adrenak.Tork/Runtime/Decorator/MotorTorqueVsSpeedConstraint.cs
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,19 @@ | ||
using UnityEngine; | ||
|
||
namespace Adrenak.Tork{ | ||
public class MotorTorqueVsSpeedConstraint : MonoBehaviour { | ||
[Tooltip("The maximum motor torque available based on the speed (KMPH)")] | ||
[SerializeField] AnimationCurve curve = AnimationCurve.Linear(0, 10000, 250, 0); | ||
|
||
[SerializeField] Motor motor; | ||
[SerializeField] new Rigidbody rigidbody; | ||
|
||
void Update(){ | ||
motor.maxTorque = GetMotorTorqueAtSpeed(rigidbody.velocity.magnitude); | ||
} | ||
|
||
public float GetMotorTorqueAtSpeed(float speed) { | ||
return curve.Evaluate(speed); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Adrenak.Tork/Runtime/Decorator/MotorTorqueVsSpeedConstraint.cs.meta
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
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
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