From 62d2658c2d034c53de041892bbf77b58a52944b7 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Sat, 7 Jun 2014 16:38:33 +0100 Subject: [PATCH] Limit vehicle top speeds --- rwengine/src/objects/VehicleObject.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rwengine/src/objects/VehicleObject.cpp b/rwengine/src/objects/VehicleObject.cpp index 3de04539..eac69de3 100644 --- a/rwengine/src/objects/VehicleObject.cpp +++ b/rwengine/src/objects/VehicleObject.cpp @@ -159,13 +159,17 @@ glm::quat VehicleObject::getRotation() const void VehicleObject::tick(float dt) { if(physVehicle) { + // todo: a real engine function + float velFac = (info->handling.maxVelocity - physVehicle->getCurrentSpeedKmHour()) / info->handling.maxVelocity; + float engineForce = info->handling.acceleration * 150.f * throttle * velFac; + for(int w = 0; w < physVehicle->getNumWheels(); ++w) { btWheelInfo& wi = physVehicle->getWheelInfo(w); if( info->handling.driveType == VehicleHandlingInfo::All || (info->handling.driveType == VehicleHandlingInfo::Forward && wi.m_bIsFrontWheel) || (info->handling.driveType == VehicleHandlingInfo::Rear && !wi.m_bIsFrontWheel)) { - physVehicle->applyEngineForce(info->handling.acceleration * 150.f * throttle, w); + physVehicle->applyEngineForce(engineForce, w); } float brakeReal = info->handling.brakeDeceleration * info->handling.mass * (wi.m_bIsFrontWheel? info->handling.brakeBias : 1.f - info->handling.brakeBias);