Skip to content

Commit

Permalink
Finished Uncharted 4 approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Vatsal Ambastha committed Sep 27, 2020
1 parent 967ee8e commit 5a1d823
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 15 deletions.
21 changes: 8 additions & 13 deletions Assets/Tork/Runtime/Core/TorkWheel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}
}
81 changes: 79 additions & 2 deletions Assets/Tork/Samples/Scenes/Demo.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5a1d823

Please sign in to comment.