From 2e48be97b67c14d322e9b523c0da257eab8f70ef Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Wed, 2 Apr 2025 17:24:13 +0200 Subject: [PATCH 1/6] add getter for steering --- Source/Engine/Physics/Actors/WheeledVehicle.cpp | 5 +++++ Source/Engine/Physics/Actors/WheeledVehicle.h | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/Source/Engine/Physics/Actors/WheeledVehicle.cpp b/Source/Engine/Physics/Actors/WheeledVehicle.cpp index 010add151..3aa7ff5ce 100644 --- a/Source/Engine/Physics/Actors/WheeledVehicle.cpp +++ b/Source/Engine/Physics/Actors/WheeledVehicle.cpp @@ -200,6 +200,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); diff --git a/Source/Engine/Physics/Actors/WheeledVehicle.h b/Source/Engine/Physics/Actors/WheeledVehicle.h index fe518a41d..bbb3026db 100644 --- a/Source/Engine/Physics/Actors/WheeledVehicle.h +++ b/Source/Engine/Physics/Actors/WheeledVehicle.h @@ -553,6 +553,12 @@ public: /// The value (-1,1 range). API_FUNCTION() void SetSteering(float value); + /// + /// 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. + /// + /// The vehicle steering. + API_FUNCTION() float GetSteering(); + /// /// 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. /// From dd281bbca8583f3ca433d8c903ba9b14d5163a1d Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Wed, 2 Apr 2025 19:12:36 +0200 Subject: [PATCH 2/6] add wheel information debug draw --- .../Engine/Physics/Actors/WheeledVehicle.cpp | 6 +++++ Source/Engine/Physics/Actors/WheeledVehicle.h | 25 ++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Physics/Actors/WheeledVehicle.cpp b/Source/Engine/Physics/Actors/WheeledVehicle.cpp index 3aa7ff5ce..08141e75e 100644 --- a/Source/Engine/Physics/Actors/WheeledVehicle.cpp +++ b/Source/Engine/Physics/Actors/WheeledVehicle.cpp @@ -424,6 +424,12 @@ void WheeledVehicle::OnDebugDrawSelected() { DEBUG_DRAW_WIRE_SPHERE(BoundingSphere(data.State.TireContactPoint, 5.0f), Color::Green, 0, false); } + + if (DisplayWheelInfo) + { + const String text = String::Format(TEXT("Index: {}\nCollider: {}"), wheelIndex, wheel.Collider->GetName()); + DEBUG_DRAW_TEXT(text, currentPos, WheelInfoColor, 10, 0); + } } } diff --git a/Source/Engine/Physics/Actors/WheeledVehicle.h b/Source/Engine/Physics/Actors/WheeledVehicle.h index bbb3026db..a3d66ff29 100644 --- a/Source/Engine/Physics/Actors/WheeledVehicle.h +++ b/Source/Engine/Physics/Actors/WheeledVehicle.h @@ -5,6 +5,7 @@ #include "Engine/Physics/Actors/RigidBody.h" #include "Engine/Physics/Colliders/Collider.h" #include "Engine/Scripting/ScriptingObjectReference.h" +#include "Engine/Core/Math/Color.h" /// /// Representation of the car vehicle that uses wheels. Built on top of the RigidBody with collider representing its chassis shape and wheels. @@ -464,10 +465,22 @@ public: API_FIELD(Attributes="EditorOrder(1), EditorDisplay(\"Vehicle\")") bool UseAnalogSteering = false; + /// + /// If checked, will draw some useful information about the wheels at the position of their colliders. + /// + API_FIELD(Attributes ="EditorOrder(2), EditorDisplay(\"Vehicle\")") + bool DisplayWheelInfo = false; + + /// + /// If checked, will draw some useful information about the wheels at the position of their colliders. + /// + API_FIELD(Attributes = "EditorOrder(3), EditorDisplay(\"Vehicle\"), VisibleIf(\"DisplayWheelInfo\")") + Color WheelInfoColor = Color::White; + /// /// Gets the vehicle driving model type. /// - API_PROPERTY(Attributes="EditorOrder(2), EditorDisplay(\"Vehicle\")") DriveTypes GetDriveType() const; + API_PROPERTY(Attributes="EditorOrder(4), EditorDisplay(\"Vehicle\")") DriveTypes GetDriveType() const; /// /// Sets the vehicle driving model type. @@ -477,12 +490,12 @@ public: /// /// Gets the vehicle wheels settings. /// - API_PROPERTY(Attributes="EditorOrder(4), EditorDisplay(\"Vehicle\")") const Array& GetWheels() const; + API_PROPERTY(Attributes="EditorOrder(5), EditorDisplay(\"Vehicle\")") const Array& GetWheels() const; /// /// Gets the vehicle drive control settings. /// - API_PROPERTY(Attributes = "EditorOrder(5), EditorDisplay(\"Vehicle\")") DriveControlSettings GetDriveControl() const; + API_PROPERTY(Attributes = "EditorOrder(6), EditorDisplay(\"Vehicle\")") DriveControlSettings GetDriveControl() const; /// /// Sets the vehicle drive control settings. @@ -497,7 +510,7 @@ public: /// /// Gets the vehicle engine settings. /// - API_PROPERTY(Attributes="EditorOrder(6), EditorDisplay(\"Vehicle\")") EngineSettings GetEngine() const; + API_PROPERTY(Attributes="EditorOrder(7), EditorDisplay(\"Vehicle\")") EngineSettings GetEngine() const; /// /// Sets the vehicle engine settings. @@ -507,7 +520,7 @@ public: /// /// Gets the vehicle differential settings. /// - API_PROPERTY(Attributes="EditorOrder(7), EditorDisplay(\"Vehicle\")") DifferentialSettings GetDifferential() const; + API_PROPERTY(Attributes="EditorOrder(8), EditorDisplay(\"Vehicle\")") DifferentialSettings GetDifferential() const; /// /// Sets the vehicle differential settings. @@ -517,7 +530,7 @@ public: /// /// Gets the vehicle gearbox settings. /// - API_PROPERTY(Attributes="EditorOrder(8), EditorDisplay(\"Vehicle\")") GearboxSettings GetGearbox() const; + API_PROPERTY(Attributes="EditorOrder(9), EditorDisplay(\"Vehicle\")") GearboxSettings GetGearbox() const; /// /// Sets the vehicle gearbox settings. From 59ac8a3f602f226036ec4075a57b5738a9a39e7b Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Wed, 2 Apr 2025 19:21:24 +0200 Subject: [PATCH 3/6] move anti roll bars into Vehicle display group --- Source/Engine/Physics/Actors/WheeledVehicle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Physics/Actors/WheeledVehicle.h b/Source/Engine/Physics/Actors/WheeledVehicle.h index a3d66ff29..dec7b75cd 100644 --- a/Source/Engine/Physics/Actors/WheeledVehicle.h +++ b/Source/Engine/Physics/Actors/WheeledVehicle.h @@ -540,7 +540,7 @@ public: // /// Sets axles anti roll bars to increase vehicle stability. /// - API_PROPERTY() void SetAntiRollBars(const Array& value); + API_PROPERTY(Attributes="EditorOrder(10), EditorDisplay(\"Vehicle\")") void SetAntiRollBars(const Array& value); // /// Gets axles anti roll bars. From a0b80c6096a569ece0b26291f450453d7218aeb7 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Wed, 2 Apr 2025 19:29:11 +0200 Subject: [PATCH 4/6] add getters for more commonly used vehicle fields --- Source/Engine/Physics/Actors/WheeledVehicle.cpp | 10 ++++++++++ Source/Engine/Physics/Actors/WheeledVehicle.h | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Source/Engine/Physics/Actors/WheeledVehicle.cpp b/Source/Engine/Physics/Actors/WheeledVehicle.cpp index 08141e75e..b3b0473f1 100644 --- a/Source/Engine/Physics/Actors/WheeledVehicle.cpp +++ b/Source/Engine/Physics/Actors/WheeledVehicle.cpp @@ -213,11 +213,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); diff --git a/Source/Engine/Physics/Actors/WheeledVehicle.h b/Source/Engine/Physics/Actors/WheeledVehicle.h index dec7b75cd..3e93f47ec 100644 --- a/Source/Engine/Physics/Actors/WheeledVehicle.h +++ b/Source/Engine/Physics/Actors/WheeledVehicle.h @@ -578,12 +578,24 @@ public: /// The value (0,1 range). API_FUNCTION() void SetBrake(float value); + /// + /// 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. + /// + /// The vehicle brake. + API_FUNCTION() float GetBrake(); + /// /// 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. /// /// The value (0,1 range). API_FUNCTION() void SetHandbrake(float value); + /// + /// 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. + /// + /// The vehicle handbrake. + API_FUNCTION() float GetHandbrake(); + /// /// 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. From 68ef6f08c6cfe6cdf09795a4fc591a009e8d65aa Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Wed, 2 Apr 2025 19:40:27 +0200 Subject: [PATCH 5/6] minor style fixes --- Source/Engine/Physics/Actors/WheeledVehicle.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Physics/Actors/WheeledVehicle.h b/Source/Engine/Physics/Actors/WheeledVehicle.h index 3e93f47ec..a9efb204d 100644 --- a/Source/Engine/Physics/Actors/WheeledVehicle.h +++ b/Source/Engine/Physics/Actors/WheeledVehicle.h @@ -468,13 +468,13 @@ public: /// /// If checked, will draw some useful information about the wheels at the position of their colliders. /// - API_FIELD(Attributes ="EditorOrder(2), EditorDisplay(\"Vehicle\")") + API_FIELD(Attributes="EditorOrder(2), EditorDisplay(\"Vehicle\")") bool DisplayWheelInfo = false; /// /// If checked, will draw some useful information about the wheels at the position of their colliders. /// - API_FIELD(Attributes = "EditorOrder(3), EditorDisplay(\"Vehicle\"), VisibleIf(\"DisplayWheelInfo\")") + API_FIELD(Attributes="EditorOrder(3), EditorDisplay(\"Vehicle\"), VisibleIf(\"DisplayWheelInfo\")") Color WheelInfoColor = Color::White; /// From 1dfd717093b53a5e1f618fca821524c8e92bd80c Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Wed, 2 Apr 2025 23:38:04 +0200 Subject: [PATCH 6/6] serialize display info and color --- Source/Engine/Physics/Actors/WheeledVehicle.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Engine/Physics/Actors/WheeledVehicle.cpp b/Source/Engine/Physics/Actors/WheeledVehicle.cpp index b3b0473f1..799f4a5d4 100644 --- a/Source/Engine/Physics/Actors/WheeledVehicle.cpp +++ b/Source/Engine/Physics/Actors/WheeledVehicle.cpp @@ -471,6 +471,8 @@ void WheeledVehicle::Serialize(SerializeStream& stream, const void* otherObj) SERIALIZE_GET_OTHER_OBJ(WheeledVehicle); + SERIALIZE_MEMBER(DisplayWheelInfo, DisplayWheelInfo); + SERIALIZE_MEMBER(WheelInfoColor, WheelInfoColor); SERIALIZE_MEMBER(DriveType, _driveType); SERIALIZE_MEMBER(Wheels, _wheels); SERIALIZE_MEMBER(DriveControl, _driveControl); @@ -486,6 +488,8 @@ void WheeledVehicle::Deserialize(DeserializeStream& stream, ISerializeModifier* { RigidBody::Deserialize(stream, modifier); + DESERIALIZE(DisplayWheelInfo); + DESERIALIZE(WheelInfoColor); DESERIALIZE_MEMBER(DriveType, _driveType); DESERIALIZE_MEMBER(Wheels, _wheels); DESERIALIZE_MEMBER(DriveControl, _driveControl);