Debian Codegraph @

scene/3d/physics/vehicle_body_3d.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* vehicle_body_3d.cpp */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #include "vehicle_body_3d.h"
32
33 #include "core/config/engine.h"
34
35 #define ROLLING_INFLUENCE_FIX
36
37 class btVehicleJacobianEntry {
38 public:
39 Vector3 m_linearJointAxis;
40 Vector3 m_aJ;
41 Vector3 m_bJ;
42 Vector3 m_0MinvJt;
43 Vector3 m_1MinvJt;
44 //Optimization: can be stored in the w/last component of one of the vectors
45 real_t m_Adiag = 0.0;
46
47 real_t getDiagonal() const { return m_Adiag; }
48
49 btVehicleJacobianEntry() {}
50 //constraint between two different rigidbodies
51 btVehicleJacobianEntry(
52 const Basis &world2A,
53 const Basis &world2B,
54 const Vector3 &rel_pos1,
55 const Vector3 &rel_pos2,
56 const Vector3 &jointAxis,
57 const Vector3 &inertiaInvA,
58 const real_t massInvA,
59 const Vector3 &inertiaInvB,
60 const real_t massInvB) :
61 m_linearJointAxis(jointAxis) {
62 m_aJ = world2A.xform(rel_pos1.cross(m_linearJointAxis));
63 m_bJ = world2B.xform(rel_pos2.cross(-m_linearJointAxis));
64 m_0MinvJt = inertiaInvA * m_aJ;
65 m_1MinvJt = inertiaInvB * m_bJ;
66 m_Adiag = massInvA + m_0MinvJt.dot(m_aJ) + massInvB + m_1MinvJt.dot(m_bJ);
67
68 //btAssert(m_Adiag > real_t(0.0));
69 }
70
71 real_t getRelativeVelocity(const Vector3 &linvelA, const Vector3 &angvelA, const Vector3 &linvelB, const Vector3 &angvelB) {
72 Vector3 linrel = linvelA - linvelB;
73 Vector3 angvela = angvelA * m_aJ;
74 Vector3 angvelb = angvelB * m_bJ;
75 linrel *= m_linearJointAxis;
76 angvela += angvelb;
77 angvela += linrel;
78 real_t rel_vel2 = angvela[0] + angvela[1] + angvela[2];
79 return rel_vel2 + CMP_EPSILON;
80 }
81 };
82
83 void VehicleWheel3D::FTIData::update_world_xform(Transform3D &r_xform, real_t p_interpolation_fraction) {
84 // Note that when unset (during the first few frames before a physics tick)
85 // the xform will be whatever it was loaded as.
86 if (!unset) {
87 real_t f = p_interpolation_fraction;
88
89 WheelXform i;
90 i.up = prev.up.lerp(curr.up, f);
91 i.up.normalize();
92 i.right = prev.right.lerp(curr.right, f);
93 i.right.normalize();
94
95 Vector3 fwd = i.up.cross(i.right);
96 fwd.normalize();
97
98 i.origin = prev.origin.lerp(curr.origin, f);
99 i.steering = Math::lerp(prev.steering, curr.steering, f);
100
101 real_t rotation = Math::lerp(curr_rotation - curr_rotation_delta, curr_rotation, f);
102
103 Basis steeringMat(i.up, i.steering);
104
105 Basis rotatingMat(i.right, rotation);
106
107 Basis basis2(
108 i.right[0], i.up[0], fwd[0],
109 i.right[1], i.up[1], fwd[1],
110 i.right[2], i.up[2], fwd[2]);
111
112 r_xform.set_basis(steeringMat * rotatingMat * basis2);
113 r_xform.set_origin(i.origin);
114 }
115 }
116
117 void VehicleWheel3D::_notification(int p_what) {
118 switch (p_what) {
119 case NOTIFICATION_ENTER_TREE: {
120 VehicleBody3D *cb = Object::cast_to<VehicleBody3D>(get_parent());
121 if (!cb) {
122 return;
123 }
124 body = cb;
125 local_xform = get_transform();
126 cb->wheels.push_back(this);
127
128 m_chassisConnectionPointCS = get_transform().origin;
129 m_wheelDirectionCS = -get_transform().basis.get_column(Vector3::AXIS_Y).normalized();
130 m_wheelAxleCS = get_transform().basis.get_column(Vector3::AXIS_X).normalized();
131 } break;
132
133 case NOTIFICATION_EXIT_TREE: {
134 VehicleBody3D *cb = Object::cast_to<VehicleBody3D>(get_parent());
135 if (!cb) {
136 return;
137 }
138 cb->wheels.erase(this);
139 body = nullptr;
140 } break;
141 }
142 }
143
144 PackedStringArray VehicleWheel3D::get_configuration_warnings() const {
145 PackedStringArray warnings = Node3D::get_configuration_warnings();
146
147 if (!Object::cast_to<VehicleBody3D>(get_parent())) {
148 warnings.push_back(RTR("VehicleWheel3D serves to provide a wheel system to a VehicleBody3D. Please use it as a child of a VehicleBody3D."));
149 }
150
151 return warnings;
152 }
153
154 void VehicleWheel3D::_update(PhysicsDirectBodyState3D *s) {
155 if (m_raycastInfo.m_isInContact) {
156 real_t project = m_raycastInfo.m_contactNormalWS.dot(m_raycastInfo.m_wheelDirectionWS);
157 Vector3 chassis_velocity_at_contactPoint;
158 Vector3 relpos = m_raycastInfo.m_contactPointWS - s->get_transform().origin;
159
160 chassis_velocity_at_contactPoint = s->get_linear_velocity() +
161 (s->get_angular_velocity()).cross(relpos); // * mPos);
162
163 real_t projVel = m_raycastInfo.m_contactNormalWS.dot(chassis_velocity_at_contactPoint);
164 if (project >= real_t(-0.1)) {
165 m_suspensionRelativeVelocity = real_t(0.0);
166 m_clippedInvContactDotSuspension = real_t(1.0) / real_t(0.1);
167 } else {
168 real_t inv = real_t(-1.) / project;
169 m_suspensionRelativeVelocity = projVel * inv;
170 m_clippedInvContactDotSuspension = inv;
171 }
172 } else { // Not in contact : position wheel in a nice (rest length) position
173 m_raycastInfo.m_suspensionLength = m_suspensionRestLength;
174 m_suspensionRelativeVelocity = real_t(0.0);
175 m_raycastInfo.m_contactNormalWS = -m_raycastInfo.m_wheelDirectionWS;
176 m_clippedInvContactDotSuspension = real_t(1.0);
177 }
178 }
179
180 void VehicleWheel3D::set_radius(real_t p_radius) {
181 m_wheelRadius = p_radius;
182 update_gizmos();
183 }
184
185 real_t VehicleWheel3D::get_radius() const {
186 return m_wheelRadius;
187 }
188
189 void VehicleWheel3D::set_suspension_rest_length(real_t p_length) {
190 m_suspensionRestLength = p_length;
191 update_gizmos();
192 }
193
194 real_t VehicleWheel3D::get_suspension_rest_length() const {
195 return m_suspensionRestLength;
196 }
197
198 void VehicleWheel3D::set_suspension_travel(real_t p_length) {
199 m_maxSuspensionTravel = p_length;
200 }
201
202 real_t VehicleWheel3D::get_suspension_travel() const {
203 return m_maxSuspensionTravel;
204 }
205
206 void VehicleWheel3D::set_suspension_stiffness(real_t p_value) {
207 m_suspensionStiffness = p_value;
208 }
209
210 real_t VehicleWheel3D::get_suspension_stiffness() const {
211 return m_suspensionStiffness;
212 }
213
214 void VehicleWheel3D::set_suspension_max_force(real_t p_value) {
215 m_maxSuspensionForce = p_value;
216 }
217
218 real_t VehicleWheel3D::get_suspension_max_force() const {
219 return m_maxSuspensionForce;
220 }
221
222 void VehicleWheel3D::set_damping_compression(real_t p_value) {
223 m_wheelsDampingCompression = p_value;
224 }
225
226 real_t VehicleWheel3D::get_damping_compression() const {
227 return m_wheelsDampingCompression;
228 }
229
230 void VehicleWheel3D::set_damping_relaxation(real_t p_value) {
231 m_wheelsDampingRelaxation = p_value;
232 }
233
234 real_t VehicleWheel3D::get_damping_relaxation() const {
235 return m_wheelsDampingRelaxation;
236 }
237
238 void VehicleWheel3D::set_friction_slip(real_t p_value) {
239 m_frictionSlip = p_value;
240 }
241
242 real_t VehicleWheel3D::get_friction_slip() const {
243 return m_frictionSlip;
244 }
245
246 void VehicleWheel3D::set_roll_influence(real_t p_value) {
247 m_rollInfluence = p_value;
248 }
249
250 real_t VehicleWheel3D::get_roll_influence() const {
251 return m_rollInfluence;
252 }
253
254 bool VehicleWheel3D::is_in_contact() const {
255 return m_raycastInfo.m_isInContact;
256 }
257
258 Vector3 VehicleWheel3D::get_contact_point() const {
259 return m_raycastInfo.m_contactPointWS;
260 }
261
262 Vector3 VehicleWheel3D::get_contact_normal() const {
263 return m_raycastInfo.m_contactNormalWS;
264 }
265
266 Node3D *VehicleWheel3D::get_contact_body() const {
267 return m_raycastInfo.m_groundObject;
268 }
269
270 void VehicleWheel3D::_bind_methods() {
271 ClassDB::bind_method(D_METHOD("set_radius", "length"), &VehicleWheel3D::set_radius);
272 ClassDB::bind_method(D_METHOD("get_radius"), &VehicleWheel3D::get_radius);
273
274 ClassDB::bind_method(D_METHOD("set_suspension_rest_length", "length"), &VehicleWheel3D::set_suspension_rest_length);
275 ClassDB::bind_method(D_METHOD("get_suspension_rest_length"), &VehicleWheel3D::get_suspension_rest_length);
276
277 ClassDB::bind_method(D_METHOD("set_suspension_travel", "length"), &VehicleWheel3D::set_suspension_travel);
278 ClassDB::bind_method(D_METHOD("get_suspension_travel"), &VehicleWheel3D::get_suspension_travel);
279
280 ClassDB::bind_method(D_METHOD("set_suspension_stiffness", "length"), &VehicleWheel3D::set_suspension_stiffness);
281 ClassDB::bind_method(D_METHOD("get_suspension_stiffness"), &VehicleWheel3D::get_suspension_stiffness);
282
283 ClassDB::bind_method(D_METHOD("set_suspension_max_force", "length"), &VehicleWheel3D::set_suspension_max_force);
284 ClassDB::bind_method(D_METHOD("get_suspension_max_force"), &VehicleWheel3D::get_suspension_max_force);
285
286 ClassDB::bind_method(D_METHOD("set_damping_compression", "length"), &VehicleWheel3D::set_damping_compression);
287 ClassDB::bind_method(D_METHOD("get_damping_compression"), &VehicleWheel3D::get_damping_compression);
288
289 ClassDB::bind_method(D_METHOD("set_damping_relaxation", "length"), &VehicleWheel3D::set_damping_relaxation);
290 ClassDB::bind_method(D_METHOD("get_damping_relaxation"), &VehicleWheel3D::get_damping_relaxation);
291
292 ClassDB::bind_method(D_METHOD("set_use_as_traction", "enable"), &VehicleWheel3D::set_use_as_traction);
293 ClassDB::bind_method(D_METHOD("is_used_as_traction"), &VehicleWheel3D::is_used_as_traction);
294
295 ClassDB::bind_method(D_METHOD("set_use_as_steering", "enable"), &VehicleWheel3D::set_use_as_steering);
296 ClassDB::bind_method(D_METHOD("is_used_as_steering"), &VehicleWheel3D::is_used_as_steering);
297
298 ClassDB::bind_method(D_METHOD("set_friction_slip", "length"), &VehicleWheel3D::set_friction_slip);
299 ClassDB::bind_method(D_METHOD("get_friction_slip"), &VehicleWheel3D::get_friction_slip);
300
301 ClassDB::bind_method(D_METHOD("is_in_contact"), &VehicleWheel3D::is_in_contact);
302 ClassDB::bind_method(D_METHOD("get_contact_body"), &VehicleWheel3D::get_contact_body);
303 ClassDB::bind_method(D_METHOD("get_contact_point"), &VehicleWheel3D::get_contact_point);
304 ClassDB::bind_method(D_METHOD("get_contact_normal"), &VehicleWheel3D::get_contact_normal);
305
306 ClassDB::bind_method(D_METHOD("set_roll_influence", "roll_influence"), &VehicleWheel3D::set_roll_influence);
307 ClassDB::bind_method(D_METHOD("get_roll_influence"), &VehicleWheel3D::get_roll_influence);
308
309 ClassDB::bind_method(D_METHOD("get_skidinfo"), &VehicleWheel3D::get_skidinfo);
310
311 ClassDB::bind_method(D_METHOD("get_rpm"), &VehicleWheel3D::get_rpm);
312
313 ClassDB::bind_method(D_METHOD("set_engine_force", "engine_force"), &VehicleWheel3D::set_engine_force);
314 ClassDB::bind_method(D_METHOD("get_engine_force"), &VehicleWheel3D::get_engine_force);
315
316 ClassDB::bind_method(D_METHOD("set_brake", "brake"), &VehicleWheel3D::set_brake);
317 ClassDB::bind_method(D_METHOD("get_brake"), &VehicleWheel3D::get_brake);
318
319 ClassDB::bind_method(D_METHOD("set_steering", "steering"), &VehicleWheel3D::set_steering);
320 ClassDB::bind_method(D_METHOD("get_steering"), &VehicleWheel3D::get_steering);
321
322 ADD_GROUP("Per-Wheel Motion", "");
323 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "engine_force", PROPERTY_HINT_RANGE, U"-1024,1024,0.01,or_less,or_greater,suffix:kg\u22C5m/s\u00B2 (N)"), "set_engine_force", "get_engine_force");
324 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "brake", PROPERTY_HINT_RANGE, U"-128,128,0.01,or_less,or_greater,suffix:kg\u22C5m/s\u00B2 (N)"), "set_brake", "get_brake");
325 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "steering", PROPERTY_HINT_RANGE, "-180,180,0.01,radians_as_degrees"), "set_steering", "get_steering");
326 ADD_GROUP("VehicleBody3D Motion", "");
327 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_as_traction"), "set_use_as_traction", "is_used_as_traction");
328 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_as_steering"), "set_use_as_steering", "is_used_as_steering");
329 ADD_GROUP("Wheel", "wheel_");
330 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "wheel_roll_influence"), "set_roll_influence", "get_roll_influence");
331 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "wheel_radius", PROPERTY_HINT_NONE, "suffix:m"), "set_radius", "get_radius");
332 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "wheel_rest_length", PROPERTY_HINT_NONE, "suffix:m"), "set_suspension_rest_length", "get_suspension_rest_length");
333 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "wheel_friction_slip"), "set_friction_slip", "get_friction_slip");
334 ADD_GROUP("Suspension", "suspension_");
335 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "suspension_travel", PROPERTY_HINT_NONE, "suffix:m"), "set_suspension_travel", "get_suspension_travel");
336 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "suspension_stiffness", PROPERTY_HINT_NONE, U"suffix:N/mm"), "set_suspension_stiffness", "get_suspension_stiffness");
337 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "suspension_max_force", PROPERTY_HINT_NONE, U"suffix:kg\u22C5m/s\u00B2 (N)"), "set_suspension_max_force", "get_suspension_max_force");
338 ADD_GROUP("Damping", "damping_");
339 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "damping_compression", PROPERTY_HINT_NONE, U"suffix:N\u22C5s/mm"), "set_damping_compression", "get_damping_compression");
340 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "damping_relaxation", PROPERTY_HINT_NONE, U"suffix:N\u22C5s/mm"), "set_damping_relaxation", "get_damping_relaxation");
341 }
342
343 void VehicleWheel3D::set_engine_force(real_t p_engine_force) {
344 m_engineForce = p_engine_force;
345 }
346
347 real_t VehicleWheel3D::get_engine_force() const {
348 return m_engineForce;
349 }
350
351 void VehicleWheel3D::set_brake(real_t p_brake) {
352 m_brake = p_brake;
353 }
354
355 real_t VehicleWheel3D::get_brake() const {
356 return m_brake;
357 }
358
359 void VehicleWheel3D::set_steering(real_t p_steering) {
360 m_steering = p_steering;
361 }
362
363 real_t VehicleWheel3D::get_steering() const {
364 return m_steering;
365 }
366
367 void VehicleWheel3D::set_use_as_traction(bool p_enable) {
368 engine_traction = p_enable;
369 }
370
371 bool VehicleWheel3D::is_used_as_traction() const {
372 return engine_traction;
373 }
374
375 void VehicleWheel3D::set_use_as_steering(bool p_enabled) {
376 steers = p_enabled;
377 }
378
379 bool VehicleWheel3D::is_used_as_steering() const {
380 return steers;
381 }
382
383 real_t VehicleWheel3D::get_skidinfo() const {
384 return m_skidInfo;
385 }
386
387 real_t VehicleWheel3D::get_rpm() const {
388 return m_rpm;
389 }
390
391 VehicleWheel3D::VehicleWheel3D() {
392 set_physics_interpolation_mode(PHYSICS_INTERPOLATION_MODE_OFF);
393 }
394
395 void VehicleBody3D::_update_wheel_transform(VehicleWheel3D &wheel, PhysicsDirectBodyState3D *s) {
396 wheel.m_raycastInfo.m_isInContact = false;
397
398 Transform3D chassisTrans = s->get_transform();
399 /*
400 if (interpolatedTransform && (getRigidBody()->getMotionState())) {
401 getRigidBody()->getMotionState()->getWorldTransform(chassisTrans);
402 }
403 */
404
405 wheel.m_raycastInfo.m_hardPointWS = chassisTrans.xform(wheel.m_chassisConnectionPointCS);
406 //wheel.m_raycastInfo.m_hardPointWS+=s->get_linear_velocity()*s->get_step();
407 wheel.m_raycastInfo.m_wheelDirectionWS = chassisTrans.get_basis().xform(wheel.m_wheelDirectionCS).normalized();
408 wheel.m_raycastInfo.m_wheelAxleWS = chassisTrans.get_basis().xform(wheel.m_wheelAxleCS).normalized();
409 }
410
411 void VehicleBody3D::_update_wheel(int p_idx, PhysicsDirectBodyState3D *s) {
412 VehicleWheel3D &wheel = *wheels[p_idx];
413 _update_wheel_transform(wheel, s);
414
415 Vector3 up = -wheel.m_raycastInfo.m_wheelDirectionWS;
416 const Vector3 &right = wheel.m_raycastInfo.m_wheelAxleWS;
417 Vector3 fwd = up.cross(right);
418 fwd = fwd.normalized();
419
420 VehicleWheel3D::FTIData &id = wheel.fti_data;
421
422 Vector3 origin = wheel.m_raycastInfo.m_hardPointWS + wheel.m_raycastInfo.m_wheelDirectionWS * wheel.m_raycastInfo.m_suspensionLength;
423
424 if (is_physics_interpolated_and_enabled()) {
425 id.curr.up = up;
426 id.curr.right = right;
427 id.curr.steering = wheel.m_steering;
428 id.curr.origin = origin;
429
430 // Pump the xform the first update to the wheel,
431 // otherwise the world xform prev will be NULL.
432 if (id.unset || id.reset_queued) {
433 id.unset = false;
434 id.reset_queued = false;
435 id.pump();
436 }
437
438 // The physics etc relies on the rest of this being correct, even with FTI,
439 // so we can't pre-maturely return here.
440 }
441
442 Basis steeringMat(up, wheel.m_steering);
443
444 Basis rotatingMat(right, wheel.m_rotation);
445
446 Basis basis2(
447 right[0], up[0], fwd[0],
448 right[1], up[1], fwd[1],
449 right[2], up[2], fwd[2]);
450
451 wheel.m_worldTransform.set_basis(steeringMat * rotatingMat * basis2);
452 //wheel.m_worldTransform.set_basis(basis2 * (steeringMat * rotatingMat));
453 wheel.m_worldTransform.set_origin(origin);
454 }
455
456 real_t VehicleBody3D::_ray_cast(int p_idx, PhysicsDirectBodyState3D *s) {
457 VehicleWheel3D &wheel = *wheels[p_idx];
458
459 _update_wheel_transform(wheel, s);
460
461 real_t depth = -1;
462
463 real_t raylen = wheel.m_suspensionRestLength + wheel.m_wheelRadius;
464
465 Vector3 rayvector = wheel.m_raycastInfo.m_wheelDirectionWS * (raylen);
466 Vector3 source = wheel.m_raycastInfo.m_hardPointWS;
467 wheel.m_raycastInfo.m_contactPointWS = source + rayvector;
468 const Vector3 &target = wheel.m_raycastInfo.m_contactPointWS;
469 source -= wheel.m_wheelRadius * wheel.m_raycastInfo.m_wheelDirectionWS;
470
471 real_t param = real_t(0.);
472
473 PhysicsDirectSpaceState3D::RayResult rr;
474
475 PhysicsDirectSpaceState3D *ss = s->get_space_state();
476
477 PhysicsDirectSpaceState3D::RayParameters ray_params;
478 ray_params.from = source;
479 ray_params.to = target;
480 ray_params.exclude = exclude;
481 ray_params.collision_mask = get_collision_mask();
482
483 wheel.m_raycastInfo.m_groundObject = nullptr;
484 bool col = ss->intersect_ray(ray_params, rr);
485
486 if (col) {
487 param = source.distance_to(rr.position) / source.distance_to(target);
488 depth = raylen * param;
489 wheel.m_raycastInfo.m_contactNormalWS = rr.normal;
490
491 wheel.m_raycastInfo.m_isInContact = true;
492 if (rr.collider) {
493 wheel.m_raycastInfo.m_groundObject = Object::cast_to<PhysicsBody3D>(rr.collider);
494 }
495
496 real_t hitDistance = param * raylen;
497 wheel.m_raycastInfo.m_suspensionLength = hitDistance - wheel.m_wheelRadius;
498 //clamp on max suspension travel
499
500 real_t minSuspensionLength = wheel.m_suspensionRestLength - wheel.m_maxSuspensionTravel;
501 real_t maxSuspensionLength = wheel.m_suspensionRestLength + wheel.m_maxSuspensionTravel;
502 if (wheel.m_raycastInfo.m_suspensionLength < minSuspensionLength) {
503 wheel.m_raycastInfo.m_suspensionLength = minSuspensionLength;
504 }
505 if (wheel.m_raycastInfo.m_suspensionLength > maxSuspensionLength) {
506 wheel.m_raycastInfo.m_suspensionLength = maxSuspensionLength;
507 }
508
509 wheel.m_raycastInfo.m_contactPointWS = rr.position;
510
511 real_t denominator = wheel.m_raycastInfo.m_contactNormalWS.dot(wheel.m_raycastInfo.m_wheelDirectionWS);
512
513 Vector3 chassis_velocity_at_contactPoint;
514 //Vector3 relpos = wheel.m_raycastInfo.m_contactPointWS-getRigidBody()->getCenterOfMassPosition();
515
516 //chassis_velocity_at_contactPoint = getRigidBody()->getVelocityInLocalPoint(relpos);
517
518 chassis_velocity_at_contactPoint = s->get_linear_velocity() +
519 (s->get_angular_velocity()).cross(wheel.m_raycastInfo.m_contactPointWS - s->get_transform().origin); // * mPos);
520
521 real_t projVel = wheel.m_raycastInfo.m_contactNormalWS.dot(chassis_velocity_at_contactPoint);
522
523 if (denominator >= real_t(-0.1)) {
524 wheel.m_suspensionRelativeVelocity = real_t(0.0);
525 wheel.m_clippedInvContactDotSuspension = real_t(1.0) / real_t(0.1);
526 } else {
527 real_t inv = real_t(-1.) / denominator;
528 wheel.m_suspensionRelativeVelocity = projVel * inv;
529 wheel.m_clippedInvContactDotSuspension = inv;
530 }
531
532 } else {
533 wheel.m_raycastInfo.m_isInContact = false;
534 //put wheel info as in rest position
535 wheel.m_raycastInfo.m_suspensionLength = wheel.m_suspensionRestLength;
536 wheel.m_suspensionRelativeVelocity = real_t(0.0);
537 wheel.m_raycastInfo.m_contactNormalWS = -wheel.m_raycastInfo.m_wheelDirectionWS;
538 wheel.m_clippedInvContactDotSuspension = real_t(1.0);
539 }
540
541 return depth;
542 }
543
544 void VehicleBody3D::_update_suspension(PhysicsDirectBodyState3D *s) {
545 real_t chassisMass = get_mass();
546
547 for (int w_it = 0; w_it < wheels.size(); w_it++) {
548 VehicleWheel3D &wheel_info = *wheels[w_it];
549
550 if (wheel_info.m_raycastInfo.m_isInContact) {
551 real_t force;
552 //Spring
553 {
554 real_t susp_length = wheel_info.m_suspensionRestLength;
555 real_t current_length = wheel_info.m_raycastInfo.m_suspensionLength;
556
557 real_t length_diff = (susp_length - current_length);
558
559 force = wheel_info.m_suspensionStiffness * length_diff * wheel_info.m_clippedInvContactDotSuspension;
560 }
561
562 // Damper
563 {
564 real_t projected_rel_vel = wheel_info.m_suspensionRelativeVelocity;
565 {
566 real_t susp_damping;
567 if (projected_rel_vel < real_t(0.0)) {
568 susp_damping = wheel_info.m_wheelsDampingCompression;
569 } else {
570 susp_damping = wheel_info.m_wheelsDampingRelaxation;
571 }
572 force -= susp_damping * projected_rel_vel;
573 }
574 }
575
576 // RESULT
577 wheel_info.m_wheelsSuspensionForce = force * chassisMass;
578 if (wheel_info.m_wheelsSuspensionForce < real_t(0.)) {
579 wheel_info.m_wheelsSuspensionForce = real_t(0.);
580 }
581 } else {
582 wheel_info.m_wheelsSuspensionForce = real_t(0.0);
583 }
584 }
585 }
586
587 //bilateral constraint between two dynamic objects
588 void VehicleBody3D::_resolve_single_bilateral(PhysicsDirectBodyState3D *s, const Vector3 &pos1,
589 PhysicsBody3D *body2, const Vector3 &pos2, const Vector3 &normal, real_t &impulse, const real_t p_rollInfluence) {
590 real_t normalLenSqr = normal.length_squared();
591 //ERR_FAIL_COND( normalLenSqr < real_t(1.1));
592
593 if (normalLenSqr > real_t(1.1)) {
594 impulse = real_t(0.);
595 return;
596 }
597
598 Vector3 rel_pos1 = pos1 - s->get_transform().origin;
599 Vector3 rel_pos2;
600 if (body2) {
601 rel_pos2 = pos2 - body2->get_global_transform().origin;
602 }
603 // This Jacobian entry could be reused for all iterations.
604
605 Vector3 vel1 = s->get_linear_velocity() + (s->get_angular_velocity()).cross(rel_pos1); // * mPos);
606 Vector3 vel2;
607
608 if (body2) {
609 vel2 = body2->get_linear_velocity() + body2->get_angular_velocity().cross(rel_pos2);
610 }
611
612 Vector3 vel = vel1 - vel2;
613
614 Basis b2trans;
615 real_t b2invmass = 0;
616 Vector3 b2lv;
617 Vector3 b2av;
618 Vector3 b2invinertia; //todo
619
620 if (body2) {
621 b2trans = body2->get_global_transform().basis.transposed();
622 b2invmass = body2->get_inverse_mass();
623 b2lv = body2->get_linear_velocity();
624 b2av = body2->get_angular_velocity();
625 }
626
627 btVehicleJacobianEntry jac(s->get_transform().basis.transposed(),
628 b2trans,
629 rel_pos1,
630 rel_pos2,
631 normal,
632 s->get_inverse_inertia_tensor().get_main_diagonal(),
633 1.0 / get_mass(),
634 b2invinertia,
635 b2invmass);
636
637 // FIXME: rel_vel assignment here is overwritten by the following assignment.
638 // What seems to be intended in the next assignment is: rel_vel = normal.dot(rel_vel);
639 // Investigate why.
640 real_t rel_vel = jac.getRelativeVelocity(
641 s->get_linear_velocity(),
642 s->get_transform().basis.transposed().xform(s->get_angular_velocity()),
643 b2lv,
644 b2trans.xform(b2av));
645
646 rel_vel = normal.dot(vel);
647
648 // !BAS! We had this set to 0.4, in bullet its 0.2
649 real_t contactDamping = real_t(0.2);
650
651 if (p_rollInfluence > 0.0) {
652 // !BAS! But seeing we apply this frame by frame, makes more sense to me to make this time based
653 // keeping in mind our anti roll factor if it is set
654 contactDamping = MIN(contactDamping, s->get_step() / p_rollInfluence);
655 }
656
657 #define ONLY_USE_LINEAR_MASS
658 #ifdef ONLY_USE_LINEAR_MASS
659 real_t massTerm = real_t(1.) / ((1.0 / get_mass()) + b2invmass);
660 impulse = -contactDamping * rel_vel * massTerm;
661 #else
662 real_t velocityImpulse = -contactDamping * rel_vel * jacDiagABInv;
663 impulse = velocityImpulse;
664 #endif
665 }
666
667 VehicleBody3D::btVehicleWheelContactPoint::btVehicleWheelContactPoint(PhysicsDirectBodyState3D *s, PhysicsBody3D *body1, const Vector3 &frictionPosWorld, const Vector3 &frictionDirectionWorld, real_t maxImpulse) :
668 m_s(s),
669 m_body1(body1),
670 m_frictionPositionWorld(frictionPosWorld),
671 m_frictionDirectionWorld(frictionDirectionWorld),
672 m_maxImpulse(maxImpulse) {
673 real_t denom0 = 0;
674 real_t denom1 = 0;
675
676 {
677 Vector3 r0 = frictionPosWorld - s->get_transform().origin;
678 Vector3 c0 = (r0).cross(frictionDirectionWorld);
679 Vector3 vec = s->get_inverse_inertia_tensor().xform_inv(c0).cross(r0);
680 denom0 = s->get_inverse_mass() + frictionDirectionWorld.dot(vec);
681 }
682
683 /* TODO: Why is this code unused?
684 if (body1) {
685 Vector3 r0 = frictionPosWorld - body1->get_global_transform().origin;
686 Vector3 c0 = (r0).cross(frictionDirectionWorld);
687 Vector3 vec = s->get_inverse_inertia_tensor().xform_inv(c0).cross(r0);
688 //denom1= body1->get_inverse_mass() + frictionDirectionWorld.dot(vec);
689
690 }
691 */
692
693 real_t relaxation = 1.f;
694 m_jacDiagABInv = relaxation / (denom0 + denom1);
695 }
696
697 real_t VehicleBody3D::_calc_rolling_friction(btVehicleWheelContactPoint &contactPoint) {
698 real_t j1 = 0.f;
699
700 const Vector3 &contactPosWorld = contactPoint.m_frictionPositionWorld;
701
702 Vector3 rel_pos1 = contactPosWorld - contactPoint.m_s->get_transform().origin;
703 Vector3 rel_pos2;
704 if (contactPoint.m_body1) {
705 rel_pos2 = contactPosWorld - contactPoint.m_body1->get_global_transform().origin;
706 }
707
708 real_t maxImpulse = contactPoint.m_maxImpulse;
709
710 Vector3 vel1 = contactPoint.m_s->get_linear_velocity() + (contactPoint.m_s->get_angular_velocity()).cross(rel_pos1); // * mPos);
711
712 Vector3 vel2;
713 if (contactPoint.m_body1) {
714 vel2 = contactPoint.m_body1->get_linear_velocity() + contactPoint.m_body1->get_angular_velocity().cross(rel_pos2);
715 }
716
717 Vector3 vel = vel1 - vel2;
718
719 real_t vrel = contactPoint.m_frictionDirectionWorld.dot(vel);
720
721 // calculate j that moves us to zero relative velocity
722 j1 = -vrel * contactPoint.m_jacDiagABInv;
723
724 return CLAMP(j1, -maxImpulse, maxImpulse);
725 }
726
727 static const real_t sideFrictionStiffness2 = real_t(1.0);
728 void VehicleBody3D::_update_friction(PhysicsDirectBodyState3D *s) {
729 //calculate the impulse, so that the wheels don't move sidewards
730 int numWheel = wheels.size();
731 if (!numWheel) {
732 return;
733 }
734
735 m_forwardWS.resize(numWheel);
736 m_axle.resize(numWheel);
737 m_forwardImpulse.resize(numWheel);
738 m_sideImpulse.resize(numWheel);
739
740 //collapse all those loops into one!
741 for (int i = 0; i < wheels.size(); i++) {
742 m_sideImpulse.write[i] = real_t(0.);
743 m_forwardImpulse.write[i] = real_t(0.);
744 }
745
746 {
747 for (int i = 0; i < wheels.size(); i++) {
748 VehicleWheel3D &wheelInfo = *wheels[i];
749
750 if (wheelInfo.m_raycastInfo.m_isInContact) {
751 //const btTransform& wheelTrans = getWheelTransformWS( i );
752
753 Basis wheelBasis0 = wheelInfo.m_worldTransform.basis; //get_global_transform().basis;
754
755 m_axle.write[i] = wheelBasis0.get_column(Vector3::AXIS_X);
756 //m_axle[i] = wheelInfo.m_raycastInfo.m_wheelAxleWS;
757
758 const Vector3 &surfNormalWS = wheelInfo.m_raycastInfo.m_contactNormalWS;
759 real_t proj = m_axle[i].dot(surfNormalWS);
760 m_axle.write[i] -= surfNormalWS * proj;
761 m_axle.write[i] = m_axle[i].normalized();
762
763 m_forwardWS.write[i] = surfNormalWS.cross(m_axle[i]);
764 m_forwardWS.write[i].normalize();
765
766 _resolve_single_bilateral(s, wheelInfo.m_raycastInfo.m_contactPointWS,
767 wheelInfo.m_raycastInfo.m_groundObject, wheelInfo.m_raycastInfo.m_contactPointWS,
768 m_axle[i], m_sideImpulse.write[i], wheelInfo.m_rollInfluence);
769
770 m_sideImpulse.write[i] *= sideFrictionStiffness2;
771 }
772 }
773 }
774
775 real_t sideFactor = real_t(1.);
776 real_t fwdFactor = 0.5;
777
778 bool sliding = false;
779 {
780 for (int wheel = 0; wheel < wheels.size(); wheel++) {
781 VehicleWheel3D &wheelInfo = *wheels[wheel];
782
783 //class btRigidBody* groundObject = (class btRigidBody*) wheelInfo.m_raycastInfo.m_groundObject;
784
785 real_t rollingFriction = 0.f;
786
787 if (wheelInfo.m_raycastInfo.m_isInContact) {
788 if (wheelInfo.m_engineForce != 0.f) {
789 rollingFriction = -wheelInfo.m_engineForce * s->get_step();
790 } else {
791 real_t defaultRollingFrictionImpulse = 0.f;
792 real_t maxImpulse = wheelInfo.m_brake ? wheelInfo.m_brake : defaultRollingFrictionImpulse;
793 btVehicleWheelContactPoint contactPt(s, wheelInfo.m_raycastInfo.m_groundObject, wheelInfo.m_raycastInfo.m_contactPointWS, m_forwardWS[wheel], maxImpulse);
794 rollingFriction = _calc_rolling_friction(contactPt);
795 }
796 }
797
798 //switch between active rolling (throttle), braking and non-active rolling friction (no throttle/break)
799
800 m_forwardImpulse.write[wheel] = real_t(0.);
801 wheelInfo.m_skidInfo = real_t(1.);
802
803 if (wheelInfo.m_raycastInfo.m_isInContact) {
804 wheelInfo.m_skidInfo = real_t(1.);
805
806 real_t maximp = wheelInfo.m_wheelsSuspensionForce * s->get_step() * wheelInfo.m_frictionSlip;
807 real_t maximpSide = maximp;
808
809 real_t maximpSquared = maximp * maximpSide;
810
811 m_forwardImpulse.write[wheel] = rollingFriction; //wheelInfo.m_engineForce* timeStep;
812
813 real_t x = (m_forwardImpulse[wheel]) * fwdFactor;
814 real_t y = (m_sideImpulse[wheel]) * sideFactor;
815
816 real_t impulseSquared = (x * x + y * y);
817
818 if (impulseSquared > maximpSquared) {
819 sliding = true;
820
821 real_t factor = maximp / Math::sqrt(impulseSquared);
822
823 wheelInfo.m_skidInfo *= factor;
824 }
825 }
826 }
827 }
828
829 if (sliding) {
830 for (int wheel = 0; wheel < wheels.size(); wheel++) {
831 if (m_sideImpulse[wheel] != real_t(0.)) {
832 if (wheels[wheel]->m_skidInfo < real_t(1.)) {
833 m_forwardImpulse.write[wheel] *= wheels[wheel]->m_skidInfo;
834 m_sideImpulse.write[wheel] *= wheels[wheel]->m_skidInfo;
835 }
836 }
837 }
838 }
839
840 // apply the impulses
841 {
842 for (int wheel = 0; wheel < wheels.size(); wheel++) {
843 VehicleWheel3D &wheelInfo = *wheels[wheel];
844
845 Vector3 rel_pos = wheelInfo.m_raycastInfo.m_contactPointWS -
846 s->get_transform().origin;
847
848 if (m_forwardImpulse[wheel] != real_t(0.)) {
849 s->apply_impulse(m_forwardWS[wheel] * (m_forwardImpulse[wheel]), rel_pos);
850 }
851 if (m_sideImpulse[wheel] != real_t(0.)) {
852 PhysicsBody3D *groundObject = wheelInfo.m_raycastInfo.m_groundObject;
853
854 Vector3 rel_pos2;
855 if (groundObject) {
856 rel_pos2 = wheelInfo.m_raycastInfo.m_contactPointWS - groundObject->get_global_transform().origin;
857 }
858
859 Vector3 sideImp = m_axle[wheel] * m_sideImpulse[wheel];
860
861 #if defined ROLLING_INFLUENCE_FIX // fix. It only worked if car's up was along Y - VT.
862 Vector3 vChassisWorldUp = s->get_transform().basis.transposed()[1]; //getRigidBody()->getCenterOfMassTransform3D().getBasis().getColumn(m_indexUpAxis);
863 rel_pos -= vChassisWorldUp * (vChassisWorldUp.dot(rel_pos) * (1.f - wheelInfo.m_rollInfluence));
864 #else
865 rel_pos[1] *= wheelInfo.m_rollInfluence; //?
866 #endif
867 s->apply_impulse(sideImp, rel_pos);
868
869 //apply friction impulse on the ground
870 //todo
871 //groundObject->applyImpulse(-sideImp,rel_pos2);
872 }
873 }
874 }
875 }
876
877 void VehicleBody3D::_physics_interpolated_changed() {
878 _update_process_mode();
879 RigidBody3D::_physics_interpolated_changed();
880 }
881
882 void VehicleBody3D::fti_pump_xform() {
883 for (int i = 0; i < wheels.size(); i++) {
884 VehicleWheel3D &w = *wheels[i];
885 w.fti_data.pump();
886 }
887
888 RigidBody3D::fti_pump_xform();
889 }
890
891 void VehicleBody3D::_update_process_mode() {
892 set_process_internal(is_physics_interpolated_and_enabled());
893 }
894
895 void VehicleBody3D::_notification(int p_what) {
896 switch (p_what) {
897 case NOTIFICATION_ENTER_TREE: {
898 _update_process_mode();
899 } break;
900 case NOTIFICATION_INTERNAL_PROCESS: {
901 #ifdef DEV_ENABLED
902 if (!is_physics_interpolated_and_enabled()) {
903 WARN_PRINT_ONCE("VehicleBody NOTIFICATION_INTERNAL_PROCESS with physics interpolation OFF. (benign)");
904 }
905 #endif
906 real_t f = Engine::get_singleton()->get_physics_interpolation_fraction();
907
908 Transform3D xform;
909 Transform3D inv_vehicle_xform = get_global_transform_interpolated().affine_inverse();
910
911 for (int i = 0; i < wheels.size(); i++) {
912 VehicleWheel3D &w = *wheels[i];
913 w.fti_data.update_world_xform(xform, f);
914 w.set_transform(inv_vehicle_xform * xform);
915 }
916 } break;
917 case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: {
918 _update_process_mode();
919 for (int i = 0; i < wheels.size(); i++) {
920 VehicleWheel3D &w = *wheels[i];
921 w.fti_data.reset_queued = true;
922 }
923 } break;
924 default:
925 break;
926 }
927 }
928
929 void VehicleBody3D::_body_state_changed(PhysicsDirectBodyState3D *p_state) {
930 RigidBody3D::_body_state_changed(p_state);
931
932 real_t step = p_state->get_step();
933
934 for (int i = 0; i < wheels.size(); i++) {
935 _update_wheel(i, p_state);
936 }
937
938 bool use_fti = is_physics_interpolated_and_enabled();
939
940 for (int i = 0; i < wheels.size(); i++) {
941 _ray_cast(i, p_state);
942 if (!use_fti) {
943 // TODO: can this path also just use world space directly instead of inverse parent space?
944 wheels[i]->set_transform(p_state->get_transform().inverse() * wheels[i]->m_worldTransform);
945 }
946 }
947
948 _update_suspension(p_state);
949
950 for (int i = 0; i < wheels.size(); i++) {
951 //apply suspension force
952 VehicleWheel3D &wheel = *wheels[i];
953
954 real_t suspensionForce = wheel.m_wheelsSuspensionForce;
955
956 if (suspensionForce > wheel.m_maxSuspensionForce) {
957 suspensionForce = wheel.m_maxSuspensionForce;
958 }
959 Vector3 impulse = wheel.m_raycastInfo.m_contactNormalWS * suspensionForce * step;
960 Vector3 relative_position = wheel.m_raycastInfo.m_contactPointWS - p_state->get_transform().origin;
961
962 p_state->apply_impulse(impulse, relative_position);
963 }
964
965 _update_friction(p_state);
966
967 for (int i = 0; i < wheels.size(); i++) {
968 VehicleWheel3D &wheel = *wheels[i];
969 Vector3 relpos = wheel.m_raycastInfo.m_hardPointWS - p_state->get_transform().origin;
970 Vector3 vel = p_state->get_linear_velocity() + (p_state->get_angular_velocity()).cross(relpos);
971
972 if (wheel.m_raycastInfo.m_isInContact) {
973 const Transform3D &chassisWorldTransform = p_state->get_transform();
974
975 // Get forward vector.
976 Vector3 fwd(
977 chassisWorldTransform.basis[0][Vector3::AXIS_Z],
978 chassisWorldTransform.basis[1][Vector3::AXIS_Z],
979 chassisWorldTransform.basis[2][Vector3::AXIS_Z]);
980
981 // Apply steering rotation to forward vector for steerable wheels.
982 if (wheel.steers) {
983 Basis steering_mat(Vector3(0, 1, 0), wheel.m_steering);
984 fwd = steering_mat.xform(fwd);
985 }
986
987 real_t proj = fwd.dot(wheel.m_raycastInfo.m_contactNormalWS);
988 fwd -= wheel.m_raycastInfo.m_contactNormalWS * proj;
989 fwd.normalize();
990
991 real_t proj2 = fwd.dot(vel);
992
993 wheel.m_deltaRotation = (proj2 * step) / (wheel.m_wheelRadius);
994 }
995
996 wheel.m_rotation += wheel.m_deltaRotation;
997 if (use_fti) {
998 wheel.fti_data.rotate(wheel.m_deltaRotation);
999 }
1000 wheel.m_rpm = ((wheel.m_deltaRotation / step) * 60) / Math::TAU;
1001
1002 wheel.m_deltaRotation *= real_t(0.99); //damping of rotation when not in contact
1003 }
1004 }
1005
1006 void VehicleBody3D::set_engine_force(real_t p_engine_force) {
1007 engine_force = p_engine_force;
1008 for (int i = 0; i < wheels.size(); i++) {
1009 VehicleWheel3D &wheelInfo = *wheels[i];
1010 if (wheelInfo.engine_traction) {
1011 wheelInfo.m_engineForce = p_engine_force;
1012 }
1013 }
1014 }
1015
1016 real_t VehicleBody3D::get_engine_force() const {
1017 return engine_force;
1018 }
1019
1020 void VehicleBody3D::set_brake(real_t p_brake) {
1021 brake = p_brake;
1022 for (int i = 0; i < wheels.size(); i++) {
1023 VehicleWheel3D &wheelInfo = *wheels[i];
1024 wheelInfo.m_brake = p_brake;
1025 }
1026 }
1027
1028 real_t VehicleBody3D::get_brake() const {
1029 return brake;
1030 }
1031
1032 void VehicleBody3D::set_steering(real_t p_steering) {
1033 m_steeringValue = p_steering;
1034 for (int i = 0; i < wheels.size(); i++) {
1035 VehicleWheel3D &wheelInfo = *wheels[i];
1036 if (wheelInfo.steers) {
1037 wheelInfo.m_steering = p_steering;
1038 }
1039 }
1040 }
1041
1042 real_t VehicleBody3D::get_steering() const {
1043 return m_steeringValue;
1044 }
1045
1046 void VehicleBody3D::_bind_methods() {
1047 ClassDB::bind_method(D_METHOD("set_engine_force", "engine_force"), &VehicleBody3D::set_engine_force);
1048 ClassDB::bind_method(D_METHOD("get_engine_force"), &VehicleBody3D::get_engine_force);
1049
1050 ClassDB::bind_method(D_METHOD("set_brake", "brake"), &VehicleBody3D::set_brake);
1051 ClassDB::bind_method(D_METHOD("get_brake"), &VehicleBody3D::get_brake);
1052
1053 ClassDB::bind_method(D_METHOD("set_steering", "steering"), &VehicleBody3D::set_steering);
1054 ClassDB::bind_method(D_METHOD("get_steering"), &VehicleBody3D::get_steering);
1055
1056 ADD_GROUP("Motion", "");
1057 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "engine_force", PROPERTY_HINT_RANGE, U"-1024,1024,0.01,or_less,or_greater,suffix:kg\u22C5m/s\u00B2 (N)"), "set_engine_force", "get_engine_force");
1058 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "brake", PROPERTY_HINT_RANGE, U"-128,128,0.01,or_less,or_greater,suffix:kg\u22C5m/s\u00B2 (N)"), "set_brake", "get_brake");
1059 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "steering", PROPERTY_HINT_RANGE, "-180,180,0.01,radians_as_degrees"), "set_steering", "get_steering");
1060 }
1061
1062 VehicleBody3D::VehicleBody3D() {
1063 exclude.insert(get_rid());
1064 set_mass(40);
1065 }