mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-18 16:32:32 +02:00
rwengine: Set the linear velocity to a zero vector when stopped
Vehicles have a tendency to move on their own when they are stopped, due to their interactions with other surfaces that result in a non-zero velocity. Since we have a threshold with the isStopped() method, fix this situation by setting the linear velocity and wheels rotation (that otherwise also rotate on their own) to zero vectors. Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
This commit is contained in:
parent
17b6c13a6a
commit
ff9ccd5f07
@ -161,6 +161,8 @@ VehicleObject::VehicleObject(GameWorld* engine, const glm::vec3& pos,
|
||||
halfFriction +
|
||||
halfFriction * (front ? info->handling.tractionBias
|
||||
: 1.f - info->handling.tractionBias);
|
||||
|
||||
wheelsRotation.push_back(0.f);
|
||||
}
|
||||
|
||||
setModel(getVehicle()->getModel());
|
||||
@ -385,8 +387,24 @@ void VehicleObject::tickPhysics(float dt) {
|
||||
brakeF = 2.f * std::min(1.f + kM, 4.f);
|
||||
}
|
||||
|
||||
if (isStopped() && std::abs(throttle) < 0.1f) {
|
||||
btVector3 v = collision->getBulletBody()->getLinearVelocity();
|
||||
v.setX(0.f);
|
||||
v.setY(0.f);
|
||||
|
||||
collision->getBulletBody()->setLinearVelocity(v);
|
||||
|
||||
for (int w = 0; w < physVehicle->getNumWheels(); ++w) {
|
||||
btWheelInfo& wi = physVehicle->getWheelInfo(w);
|
||||
wi.m_rotation = wheelsRotation[w];
|
||||
}
|
||||
}
|
||||
|
||||
for (int w = 0; w < physVehicle->getNumWheels(); ++w) {
|
||||
btWheelInfo& wi = physVehicle->getWheelInfo(w);
|
||||
|
||||
wheelsRotation[w] = wi.m_rotation;
|
||||
|
||||
if (info->handling.driveType == VehicleHandlingInfo::All ||
|
||||
(info->handling.driveType == VehicleHandlingInfo::Forward &&
|
||||
wi.m_bIsFrontWheel) ||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <LinearMath/btScalar.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
@ -36,6 +37,7 @@ private:
|
||||
float throttle{0.f};
|
||||
float brake{0.f};
|
||||
bool handbrake = true;
|
||||
std::vector<btScalar> wheelsRotation;
|
||||
|
||||
Atomic* chassishigh_ = nullptr;
|
||||
Atomic* chassislow_ = nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user