From 5a1d8239b52119d4dae076c4206332278aed0326 Mon Sep 17 00:00:00 2001 From: Vatsal Ambastha Date: Sun, 27 Sep 2020 10:10:37 +0530 Subject: [PATCH] Finished Uncharted 4 approach --- Assets/Tork/Runtime/Core/TorkWheel.cs | 21 +++---- Assets/Tork/Samples/Scenes/Demo.unity | 81 ++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 15 deletions(-) diff --git a/Assets/Tork/Runtime/Core/TorkWheel.cs b/Assets/Tork/Runtime/Core/TorkWheel.cs index 4108a28..2b0d2b3 100644 --- a/Assets/Tork/Runtime/Core/TorkWheel.cs +++ b/Assets/Tork/Runtime/Core/TorkWheel.cs @@ -134,6 +134,7 @@ public class TorkWheel : MonoBehaviour { public Vector3 SuspensionForce { get; private set; } public float frictionCoeff; + public float driftiness; Ray m_Ray; new Rigidbody rigidbody; @@ -223,30 +224,24 @@ void CalculateFriction() { var Vf = Vector3.Project(Velocity, forward).magnitude; var Vl = Vector3.Project(Velocity, right).magnitude; var N = SuspensionForce.magnitude; - var f = frictionCoeff; - var Favail = N * f; + var Favail = N * frictionCoeff; var Ff = MotorTorque / radius; - var Fl = Vl / Vf * N; + var Fl = Vl / Vf * N * frictionCoeff; var Ft = Mathf.Sqrt(Ff * Ff + Fl * Fl); var Fs = Favail / Ft; - var Fmax = Ft * Fs; var Flapplied = Fl * Fs; var Ffmax = Ff * Fs; - var Ffa = Mathf.Clamp(Ff, 0, Ffmax); + float Ffa; + if (Ff > 0) + Ffa = Mathf.Clamp(Ff, 0, Ffmax); + else + Ffa = Mathf.Clamp(Ff, Ffmax, 0); rigidbody.AddForceAtPosition(-Vector3.Project(Velocity, right).normalized * Flapplied, Hit.point); - //-Vector3.Project(Velocity, right).normalized * Flapplied, Hit.point); - Debug.Log(Ffa); rigidbody.AddForceAtPosition(forward * Ffa * engineShaftToWheelRatio, Hit.point); - //-Vector3.Project(Velocity, forward).normalized * Fla, Hit.point); - - //if (Fld > 0) - // Debug.Log("Spinning"); - //else - // Debug.Log("Breaking"); } } } \ No newline at end of file diff --git a/Assets/Tork/Samples/Scenes/Demo.unity b/Assets/Tork/Samples/Scenes/Demo.unity index 0dd445d..db67b26 100644 --- a/Assets/Tork/Samples/Scenes/Demo.unity +++ b/Assets/Tork/Samples/Scenes/Demo.unity @@ -2595,6 +2595,18 @@ Transform: m_Father: {fileID: 1193580804} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1151711987 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 114480416164222720, guid: 58b5a3e507c7b68449674674e18cab44, + type: 3} + m_PrefabInstance: {fileID: 2072883566} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1da1bb9a22dc0004c803629affe1f6df, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &1193580803 GameObject: m_ObjectHideFlags: 0 @@ -4000,7 +4012,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: b3b85e25256fd4e4da7311f52bde51c4, type: 3} m_Name: m_EditorClassIdentifier: - m_Vehicle: {fileID: 0} + m_Vehicle: {fileID: 1151711987} --- !u!4 &2016063157 Transform: m_ObjectHideFlags: 0 @@ -4028,7 +4040,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1132797446414550, guid: 58b5a3e507c7b68449674674e18cab44, type: 3} propertyPath: m_IsActive - value: 0 + value: 1 objectReference: {fileID: 0} - target: {fileID: 4261489924384528, guid: 58b5a3e507c7b68449674674e18cab44, type: 3} propertyPath: m_LocalPosition.x @@ -4214,6 +4226,21 @@ PrefabInstance: propertyPath: curve2.m_Curve.Array.data[3].inWeight value: 0.22396031 objectReference: {fileID: 0} + - target: {fileID: 1954840075906366550, guid: 58b5a3e507c7b68449674674e18cab44, + type: 3} + propertyPath: frictionCoeff + value: 0.8 + objectReference: {fileID: 0} + - target: {fileID: 1954840075906366550, guid: 58b5a3e507c7b68449674674e18cab44, + type: 3} + propertyPath: forwardFrictionCoeff + value: 0.9 + objectReference: {fileID: 0} + - target: {fileID: 1954840075906366550, guid: 58b5a3e507c7b68449674674e18cab44, + type: 3} + propertyPath: lateralFrictionCoeff + value: 0.75 + objectReference: {fileID: 0} - target: {fileID: 1955367046092286648, guid: 58b5a3e507c7b68449674674e18cab44, type: 3} propertyPath: curve2.m_Curve.Array.size @@ -4344,6 +4371,21 @@ PrefabInstance: propertyPath: curve2.m_Curve.Array.data[3].inWeight value: 0.22396031 objectReference: {fileID: 0} + - target: {fileID: 1955367046092286648, guid: 58b5a3e507c7b68449674674e18cab44, + type: 3} + propertyPath: frictionCoeff + value: 0.8 + objectReference: {fileID: 0} + - target: {fileID: 1955367046092286648, guid: 58b5a3e507c7b68449674674e18cab44, + type: 3} + propertyPath: forwardFrictionCoeff + value: 0.9 + objectReference: {fileID: 0} + - target: {fileID: 1955367046092286648, guid: 58b5a3e507c7b68449674674e18cab44, + type: 3} + propertyPath: lateralFrictionCoeff + value: 0.75 + objectReference: {fileID: 0} - target: {fileID: 1954582843850377584, guid: 58b5a3e507c7b68449674674e18cab44, type: 3} propertyPath: curve2.m_Curve.Array.size @@ -4474,6 +4516,21 @@ PrefabInstance: propertyPath: curve2.m_Curve.Array.data[3].inWeight value: 0.22396031 objectReference: {fileID: 0} + - target: {fileID: 1954582843850377584, guid: 58b5a3e507c7b68449674674e18cab44, + type: 3} + propertyPath: frictionCoeff + value: 0.8 + objectReference: {fileID: 0} + - target: {fileID: 1954582843850377584, guid: 58b5a3e507c7b68449674674e18cab44, + type: 3} + propertyPath: forwardFrictionCoeff + value: 0.9 + objectReference: {fileID: 0} + - target: {fileID: 1954582843850377584, guid: 58b5a3e507c7b68449674674e18cab44, + type: 3} + propertyPath: lateralFrictionCoeff + value: 0.75 + objectReference: {fileID: 0} - target: {fileID: 1955409033215586952, guid: 58b5a3e507c7b68449674674e18cab44, type: 3} propertyPath: curve2.m_Curve.Array.size @@ -4604,11 +4661,31 @@ PrefabInstance: propertyPath: curve2.m_Curve.Array.data[3].inWeight value: 0.22396031 objectReference: {fileID: 0} + - target: {fileID: 1955409033215586952, guid: 58b5a3e507c7b68449674674e18cab44, + type: 3} + propertyPath: frictionCoeff + value: 0.8 + objectReference: {fileID: 0} + - target: {fileID: 1955409033215586952, guid: 58b5a3e507c7b68449674674e18cab44, + type: 3} + propertyPath: forwardFrictionCoeff + value: 0.9 + objectReference: {fileID: 0} + - target: {fileID: 1955409033215586952, guid: 58b5a3e507c7b68449674674e18cab44, + type: 3} + propertyPath: lateralFrictionCoeff + value: 0.75 + objectReference: {fileID: 0} - target: {fileID: 1214198106691927564, guid: 58b5a3e507c7b68449674674e18cab44, type: 3} propertyPath: m_Enabled value: 0 objectReference: {fileID: 0} + - target: {fileID: 1214198106513114726, guid: 58b5a3e507c7b68449674674e18cab44, + type: 3} + propertyPath: maxTorque + value: 350 + objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 58b5a3e507c7b68449674674e18cab44, type: 3} --- !u!1 &2079960472