Skip to content

Commit

Permalink
Cumulative error avoidance at sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
mackierx111 committed Dec 11, 2022
1 parent e29372c commit b6ccc8e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,7 @@ MonoBehaviour:
centerOfMassTransform: {fileID: 2963107001226707149}
useInertia: 0
inertia: {x: 0, y: 0, z: 0}
sleepVelocityThreshold: 0.04
sleepVelocityThreshold: 0.02
SkiddingCancelRate: 0.606
frontAxle:
leftWheel: {fileID: 2963107000584003440}
Expand Down
15 changes: 15 additions & 0 deletions Assets/AWSIM/Scripts/Vehicles/Vehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ public class Axle
Vector3 lastPosition;
Quaternion lastRotation;

// Sleep position & rotation
Vector3 sleepPositon;
Quaternion sleepRotation;
bool lastSleep;

void Awake()
{
m_rigidbody = GetComponent<Rigidbody>();
Expand Down Expand Up @@ -254,6 +259,7 @@ void FixedUpdate()
lastVelocity = m_rigidbody.velocity;
lastPosition = m_transform.position;
lastRotation = m_transform.rotation;
lastSleep = sleep;

// ----- inner methods -----

Expand Down Expand Up @@ -340,6 +346,12 @@ bool IsCanSleepInput()

void UpdateVehicleSleep(bool isSleep)
{
if (isSleep == true && lastSleep == false)
{
sleepPositon = transform.position;
sleepRotation = transform.rotation;
}

// Vehicle sleep.
if (isSleep)
{
Expand All @@ -348,6 +360,9 @@ void UpdateVehicleSleep(bool isSleep)

m_rigidbody.Sleep();
m_rigidbody.constraints = RigidbodyConstraints.FreezeAll;

transform.position = sleepPositon;
transform.rotation = sleepRotation;
}
else
{
Expand Down

0 comments on commit b6ccc8e

Please sign in to comment.