1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-26 04:12:41 +01:00

rwengine: Implement actual braking when the vehicle is going forward

This implements proper braking by detecting a brake condition with a
negative throttle and a positive forward velocity. Under this condition,
the engine is stopped and brake is applied. A mass coefficient is
introduced to quantify how heavy a vehicle is, so that more braking can
be applied to heavy vehicles, that have higher inertia.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
This commit is contained in:
Paul Kocialkowski 2018-08-01 23:42:23 +02:00
parent 094513681b
commit 6c66f61519

View File

@ -308,9 +308,13 @@ void VehicleObject::tickPhysics(float dt) {
// todo: a real engine function
float velFac = info->handling.maxVelocity;
float velocity = collision->getBulletBody()->getLinearVelocity().length();
float velocityForward = physVehicle->getCurrentSpeedKmHour() / 3.6f;
float velocityMax = velFac / 9.f;
float engineForce = info->handling.acceleration * throttle * velFac;
float brakeF = getBraking();
// Mass coefficient, that quantifies how heavy a vehicle is and excludes
// light vehicles.
float kM = (std::max(1500.f, info->handling.mass) - 1500.f) / 1500.f;
if (velocity > velocityMax) {
btVector3 v = collision->getBulletBody()->getLinearVelocity().normalized();
@ -323,6 +327,9 @@ void VehicleObject::tickPhysics(float dt) {
if (handbrake) {
brakeF = 5.f;
} else if (throttle < 0.f && velocityForward > velocityMax / 8.f) {
engineForce = 0.f;
brakeF = 2.f * std::min(1.f + kM, 4.f);
}
for (int w = 0; w < physVehicle->getNumWheels(); ++w) {
@ -336,7 +343,7 @@ void VehicleObject::tickPhysics(float dt) {
}
float brakeReal =
5.f * info->handling.brakeDeceleration *
8.f * info->handling.brakeDeceleration *
(wi.m_bIsFrontWheel ? info->handling.brakeBias
: 1.f - info->handling.brakeBias);
physVehicle->setBrake(brakeReal * brakeF, w);