summaryrefslogtreecommitdiff
path: root/scene/3d/vehicle_body.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/3d/vehicle_body.cpp')
-rw-r--r--scene/3d/vehicle_body.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/scene/3d/vehicle_body.cpp b/scene/3d/vehicle_body.cpp
index c7f7b14a8f..89e96e0227 100644
--- a/scene/3d/vehicle_body.cpp
+++ b/scene/3d/vehicle_body.cpp
@@ -270,6 +270,8 @@ void VehicleWheel::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_skidinfo"), &VehicleWheel::get_skidinfo);
+ ClassDB::bind_method(D_METHOD("get_rpm"), &VehicleWheel::get_rpm);
+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_as_traction"), "set_use_as_traction", "is_used_as_traction");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_as_steering"), "set_use_as_steering", "is_used_as_steering");
ADD_GROUP("Wheel", "wheel_");
@@ -311,6 +313,11 @@ float VehicleWheel::get_skidinfo() const {
return m_skidInfo;
}
+float VehicleWheel::get_rpm() const {
+
+ return m_rpm;
+}
+
VehicleWheel::VehicleWheel() {
steers = false;
@@ -578,7 +585,7 @@ void VehicleBody::_resolve_single_bilateral(PhysicsDirectBodyState *s, const Vec
if (p_rollInfluence > 0.0) {
// !BAS! But seeing we apply this frame by frame, makes more sense to me to make this time based
// keeping in mind our anti roll factor if it is set
- contactDamping = s->get_step() / p_rollInfluence;
+ contactDamping = MIN(contactDamping, s->get_step() / p_rollInfluence);
}
#define ONLY_USE_LINEAR_MASS
@@ -716,7 +723,7 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) {
real_t rollingFriction = 0.f;
if (wheelInfo.m_raycastInfo.m_isInContact) {
- if (engine_force != 0.f) {
+ if (engine_force != 0.f && wheelInfo.engine_traction) {
rollingFriction = -engine_force * s->get_step();
} else {
real_t defaultRollingFrictionImpulse = 0.f;
@@ -865,12 +872,11 @@ void VehicleBody::_direct_state_changed(Object *p_state) {
real_t proj2 = fwd.dot(vel);
wheel.m_deltaRotation = (proj2 * step) / (wheel.m_wheelRadius);
- wheel.m_rotation += wheel.m_deltaRotation;
-
- } else {
- wheel.m_rotation += wheel.m_deltaRotation;
}
+ wheel.m_rotation += wheel.m_deltaRotation;
+ wheel.m_rpm = ((wheel.m_deltaRotation / step) * 60) / Math_TAU;
+
wheel.m_deltaRotation *= real_t(0.99); //damping of rotation when not in contact
}
@@ -922,8 +928,7 @@ void VehicleBody::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "steering", PROPERTY_HINT_RANGE, "-180,180.0,0.01"), "set_steering", "get_steering");
}
-VehicleBody::VehicleBody() :
- RigidBody() {
+VehicleBody::VehicleBody() {
m_pitchControl = 0;
m_currentVehicleSpeedKmHour = real_t(0.);