Merge branch 'SmallVehicleImprovements' of https://github.com/xxSeys1/FlaxEngine into xxSeys1-SmallVehicleImprovements

# Conflicts:
#	Source/Engine/Physics/Actors/WheeledVehicle.h
This commit is contained in:
Wojtek Figat
2025-09-22 16:18:12 +02:00
2 changed files with 57 additions and 9 deletions

View File

@@ -201,6 +201,11 @@ void WheeledVehicle::SetSteering(float value)
_steering = Math::Clamp(value, -1.0f, 1.0f);
}
float WheeledVehicle::GetSteering()
{
return _steering;
}
void WheeledVehicle::SetBrake(float value)
{
value = Math::Saturate(value);
@@ -209,11 +214,21 @@ void WheeledVehicle::SetBrake(float value)
_tankRightBrake = value;
}
float WheeledVehicle::GetBrake()
{
return _brake;
}
void WheeledVehicle::SetHandbrake(float value)
{
_handBrake = Math::Saturate(value);
}
float WheeledVehicle::GetHandbrake()
{
return _handBrake;
}
void WheeledVehicle::SetTankLeftThrottle(float value)
{
_tankLeftThrottle = Math::Clamp(value, -1.0f, 1.0f);
@@ -387,6 +402,7 @@ void WheeledVehicle::DrawPhysicsDebug(RenderView& view)
void WheeledVehicle::OnDebugDrawSelected()
{
// Wheels shapes
int32 wheelIndex = 0;
for (const auto& wheel : _wheels)
{
if (wheel.Collider && wheel.Collider->GetParent() == this && !wheel.Collider->GetIsTrigger())
@@ -423,14 +439,20 @@ void WheeledVehicle::OnDebugDrawSelected()
{
DEBUG_DRAW_WIRE_SPHERE(BoundingSphere(data.State.TireContactPoint, 5.0f), Color::Green, 0, false);
}
if (ShowDebugDrawWheelNames)
{
const String text = String::Format(TEXT("Index: {}\nCollider: {}"), wheelIndex, wheel.Collider->GetName());
DEBUG_DRAW_TEXT(text, currentPos, Color::Blue, 10, 0);
}
}
wheelIndex++;
}
// Anti roll bars axes
const int32 wheelsCount = _wheels.Count();
for (int32 i = 0; i < GetAntiRollBars().Count(); i++)
for (int32 i = 0; i < _antiRollBars.Count(); i++)
{
const int32 axleIndex = GetAntiRollBars()[i].Axle;
const int32 axleIndex = _antiRollBars[i].Axle;
const int32 leftWheelIndex = axleIndex * 2;
const int32 rightWheelIndex = leftWheelIndex + 1;
if (leftWheelIndex >= wheelsCount || rightWheelIndex >= wheelsCount)

View File

@@ -468,10 +468,18 @@ public:
API_FIELD(Attributes="EditorOrder(1), EditorDisplay(\"Vehicle\")")
bool UseAnalogSteering = false;
#if USE_EDITOR
/// <summary>
/// If checked, will draw wheel names and indices at the position of their colliders.
/// </summary>
API_FIELD(Attributes="EditorOrder(2), EditorDisplay(\"Vehicle\")")
bool ShowDebugDrawWheelNames = false;
#endif
/// <summary>
/// Gets the vehicle driving model type.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(2), EditorDisplay(\"Vehicle\")") DriveTypes GetDriveType() const;
API_PROPERTY(Attributes="EditorOrder(4), EditorDisplay(\"Vehicle\")") DriveTypes GetDriveType() const;
/// <summary>
/// Sets the vehicle driving model type.
@@ -481,12 +489,12 @@ public:
/// <summary>
/// Gets the vehicle wheels settings.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(4), EditorDisplay(\"Vehicle\")") const Array<Wheel>& GetWheels() const;
API_PROPERTY(Attributes="EditorOrder(5), EditorDisplay(\"Vehicle\")") const Array<Wheel>& GetWheels() const;
/// <summary>
/// Gets the vehicle drive control settings.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(5), EditorDisplay(\"Vehicle\")") DriveControlSettings GetDriveControl() const;
API_PROPERTY(Attributes="EditorOrder(6), EditorDisplay(\"Vehicle\")") DriveControlSettings GetDriveControl() const;
/// <summary>
/// Sets the vehicle drive control settings.
@@ -501,7 +509,7 @@ public:
/// <summary>
/// Gets the vehicle engine settings.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(6), EditorDisplay(\"Vehicle\")") EngineSettings GetEngine() const;
API_PROPERTY(Attributes="EditorOrder(7), EditorDisplay(\"Vehicle\")") EngineSettings GetEngine() const;
/// <summary>
/// Sets the vehicle engine settings.
@@ -511,7 +519,7 @@ public:
/// <summary>
/// Gets the vehicle differential settings.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(7), EditorDisplay(\"Vehicle\")") DifferentialSettings GetDifferential() const;
API_PROPERTY(Attributes="EditorOrder(8), EditorDisplay(\"Vehicle\")") DifferentialSettings GetDifferential() const;
/// <summary>
/// Sets the vehicle differential settings.
@@ -521,7 +529,7 @@ public:
/// <summary>
/// Gets the vehicle gearbox settings.
/// </summary>
API_PROPERTY(Attributes="EditorOrder(8), EditorDisplay(\"Vehicle\")") GearboxSettings GetGearbox() const;
API_PROPERTY(Attributes="EditorOrder(9), EditorDisplay(\"Vehicle\")") GearboxSettings GetGearbox() const;
/// <summary>
/// Sets the vehicle gearbox settings.
@@ -531,7 +539,7 @@ public:
// <summary>
/// Sets axles anti roll bars to increase vehicle stability.
/// </summary>
API_PROPERTY() void SetAntiRollBars(const Array<AntiRollBar>& value);
API_PROPERTY(Attributes="EditorOrder(10), EditorDisplay(\"Vehicle\")") void SetAntiRollBars(const Array<AntiRollBar>& value);
// <summary>
/// Gets axles anti roll bars.
@@ -557,18 +565,36 @@ public:
/// <param name="value">The value (-1,1 range).</param>
API_FUNCTION() void SetSteering(float value);
/// <summary>
/// Gets the vehicle steering. Steer is the analog steer value in range (-1,1) where -1 represents the steering wheel at left lock and +1 represents the steering wheel at right lock.
/// </summary>
/// <returns>The vehicle steering.</returns>
API_FUNCTION() float GetSteering();
/// <summary>
/// Sets the input for vehicle brakes. Brake is the analog brake pedal value in range (0,1) where 1 represents the pedal fully pressed and 0 represents the pedal in its rest state.
/// </summary>
/// <param name="value">The value (0,1 range).</param>
API_FUNCTION() void SetBrake(float value);
/// <summary>
/// Gets the vehicle brakes. Brake is the analog brake pedal value in range (0,1) where 1 represents the pedal fully pressed and 0 represents the pedal in its rest state.
/// </summary>
/// <returns>The vehicle brake.</returns>
API_FUNCTION() float GetBrake();
/// <summary>
/// Sets the input for vehicle handbrake. Handbrake is the analog handbrake value in range (0,1) where 1 represents the handbrake fully engaged and 0 represents the handbrake in its rest state.
/// </summary>
/// <param name="value">The value (0,1 range).</param>
API_FUNCTION() void SetHandbrake(float value);
/// <summary>
/// Gets the vehicle handbrake. Handbrake is the analog handbrake value in range (0,1) where 1 represents the handbrake fully engaged and 0 represents the handbrake in its rest state.
/// </summary>
/// <returns>The vehicle handbrake.</returns>
API_FUNCTION() float GetHandbrake();
/// <summary>
/// Sets the input for tank left track throttle. It is the analog accelerator pedal value in range (-1,1) where 1 represents the pedal fully pressed to move to forward, 0 to represents the
/// pedal in its rest state and -1 represents the pedal fully pressed to move to backward. The track direction will be inverted if the vehicle current gear is rear.