Skip to content

Commit

Permalink
Traktor: Fixed issue with slip angle calculation and going in reverse.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Jan 9, 2024
1 parent a2e938b commit af1dc55
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions code/Physics/World/Vehicle/VehicleComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void VehicleComponent::update(const world::UpdateParams& update)
if (!body)
return;

const float dT = update.deltaTime;
const float dT = (float)update.deltaTime;

updateSteering(body, dT);
updateSuspension(body, dT);
Expand Down Expand Up @@ -317,15 +317,15 @@ void VehicleComponent::updateFriction(Body* body, float dT)

Scalar rollingFriction = 0.0_simd;
const Scalar totalMass = 1.0_simd / Scalar(body->getInverseMass());
const Scalar massPerWheel = totalMass / Scalar(m_wheels.size());
const Scalar massPerWheel = totalMass / Scalar((float)m_wheels.size());
const Scalar breakingForce(m_data->getBreakingForce());

for (auto wheel : m_wheels)
{
wheel->sliding = false;

// Do not apply friction if wheel is not in contact with ground.
if (!wheel->contact)
if (!wheel->contact || wheel->grip <= 0.0f)
continue;

const WheelData* data = wheel->data;
Expand Down Expand Up @@ -358,8 +358,7 @@ void VehicleComponent::updateFriction(Body* body, float dT)
const Scalar method = clamp(1.0_simd - abs(forwardVelocity) / c_methodLimit, 0.0_simd, 1.0_simd);

// Calculate slip angle.
const float k = std::atan2(sideVelocity, forwardVelocity);
const float slipAngle = abs(k);
const float slipAngle = std::atan2(abs(sideVelocity), abs(forwardVelocity));

// Calculate amount of force from slip angle. \fixme Should use curves.
const float peakSlipFriction = data->getSlipCornerForce();
Expand All @@ -379,14 +378,14 @@ void VehicleComponent::updateFriction(Body* body, float dT)

// Apply friction force.
body->addForceAt(
bodyT * wheel->center, //wheel->contactPosition,
bodyT * wheel->center,
directionPerpW * Scalar(force * sign(-sideVelocity)) * grip * (1.0_simd - method),
false
);

// Apply perpendicular friction force if going slow.
body->addForceAt(
bodyT * wheel->center, //wheel->contactPosition,
bodyT * wheel->center,
directionPerpW * -sideVelocity * Scalar(peakSlipFriction) * grip * method,
false
);
Expand Down

0 comments on commit af1dc55

Please sign in to comment.