MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / UpdateVehicles

Method UpdateVehicles

Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp:751–1197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

749}
750
751void ScenePhysX::UpdateVehicles(float dt)
752{
753 if (WheelVehicles.IsEmpty())
754 return;
755 PROFILE_CPU_NAMED("Physics.Vehicles");
756 PROFILE_MEM(Physics);
757
758 // Update vehicles steering
759 WheelVehiclesCache.Clear();
760 WheelVehiclesCache.EnsureCapacity(WheelVehicles.Count());
761 int32 wheelsCount = 0;
762 for (auto wheelVehicle : WheelVehicles)
763 {
764 if (!wheelVehicle->IsActiveInHierarchy() || !wheelVehicle->GetEnableSimulation())
765 continue;
766 auto drive = (PxVehicleWheels*)wheelVehicle->_vehicle;
767 ASSERT(drive);
768 WheelVehiclesCache.Add(drive);
769 wheelsCount += drive->mWheelsSimData.getNbWheels();
770
771 const float deadZone = 0.1f;
772 bool isTank = wheelVehicle->_driveType == WheeledVehicle::DriveTypes::Tank;
773 float throttle = wheelVehicle->_throttle;
774 float steering = wheelVehicle->_steering;
775 float brake = wheelVehicle->_brake;
776 float leftThrottle = wheelVehicle->_tankLeftThrottle;
777 float rightThrottle = wheelVehicle->_tankRightThrottle;
778 float leftBrake = Math::Max(wheelVehicle->_tankLeftBrake, wheelVehicle->_handBrake);
779 float rightBrake = Math::Max(wheelVehicle->_tankRightBrake, wheelVehicle->_handBrake);
780 WheeledVehicle::DriveModes vehicleDriveMode = wheelVehicle->_driveControl.DriveMode;
781
782 if (isTank)
783 {
784 // Converting default vehicle controls to tank controls.
785 if (throttle != 0 || steering != 0)
786 {
787 leftThrottle = Math::Clamp(throttle + steering, -1.0f, 1.0f);
788 rightThrottle = Math::Clamp(throttle - steering, -1.0f, 1.0f);
789 }
790 }
791
792 // Converting special tank drive mode to standard tank mode when is turning.
793 if (isTank && vehicleDriveMode == WheeledVehicle::DriveModes::Standard)
794 {
795 // Special inputs when turning vehicle -1 1 to left or 1 -1 to turn right
796 // to:
797 // Standard inputs when turning vehicle 0 1 to left or 1 0 to turn right
798
799 if (leftThrottle < -deadZone && rightThrottle > deadZone)
800 {
801 leftThrottle = 0;
802 leftBrake = 1;
803 }
804 else if (leftThrottle > deadZone && rightThrottle < -deadZone)
805 {
806 rightThrottle = 0;
807 rightBrake = 1;
808 }

Callers 1

SimulationStepDoneMethod · 0.80

Calls 15

ClampFunction · 0.85
RoundTo2DecimalPlacesFunction · 0.85
P2CFunction · 0.85
getNbWheelsMethod · 0.80
GetForwardSpeedMethod · 0.80
GetCurrentGearMethod · 0.80
GetTargetGearMethod · 0.80
SetCurrentGearMethod · 0.80
GetPhysicsShapeMethod · 0.80
SetLocalTransformMethod · 0.80
MaxFunction · 0.50

Tested by

no test coverage detected