feat: added variables and properties
This commit is contained in:
parent
d1c52c7e80
commit
b5293e8bae
|
@ -1,12 +1,56 @@
|
|||
#include "car_physics.hpp"
|
||||
#include <godot_cpp/classes/curve.hpp>
|
||||
namespace godot {
|
||||
void CarPhysics::_bind_methods() {
|
||||
#define CLASSNAME CarPhysics
|
||||
GDPROPERTY_HINTED(oversteer_curve, Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Curve");
|
||||
GDPROPERTY_HINTED(understeer_curve, Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Curve");
|
||||
}
|
||||
|
||||
void CarPhysics::_enter_tree() {
|
||||
this->set_use_custom_integrator(true);
|
||||
}
|
||||
|
||||
void CarPhysics::_integrate_forces(PhysicsDirectBodyState3D *state) {
|
||||
|
||||
void CarPhysics::set_target_speed(float target) {
|
||||
this->target_speed = target;
|
||||
}
|
||||
|
||||
float CarPhysics::get_target_speed() const {
|
||||
return this->target_speed;
|
||||
}
|
||||
|
||||
void CarPhysics::set_current_steering(float steering) {
|
||||
this->current_steering = steering;
|
||||
}
|
||||
|
||||
float CarPhysics::get_current_steering() const {
|
||||
return this->current_steering;
|
||||
}
|
||||
|
||||
void CarPhysics::set_brake(bool brake) {
|
||||
this->brake = brake;
|
||||
}
|
||||
|
||||
bool CarPhysics::get_brake() const {
|
||||
return this->brake;
|
||||
}
|
||||
|
||||
void CarPhysics::set_oversteer_curve(Ref<Curve> curve) {
|
||||
this->oversteer_curve = curve;
|
||||
}
|
||||
|
||||
Ref<Curve> CarPhysics::get_oversteer_curve() const {
|
||||
return this->oversteer_curve;
|
||||
}
|
||||
|
||||
void CarPhysics::set_understeer_curve(Ref<Curve> curve) {
|
||||
this->understeer_curve = curve;
|
||||
}
|
||||
|
||||
Ref<Curve> CarPhysics::get_understeer_curve() const {
|
||||
return this->understeer_curve;
|
||||
}
|
||||
|
||||
const float CarPhysics::ACCELERATION{20.f};
|
||||
|
|
|
@ -8,7 +8,25 @@ class CarPhysics : public RigidBody3D {
|
|||
public:
|
||||
virtual void _enter_tree() override;
|
||||
virtual void _integrate_forces(PhysicsDirectBodyState3D *state) override;
|
||||
void set_target_speed(float target);
|
||||
float get_target_speed() const;
|
||||
void set_current_steering(float steering);
|
||||
float get_current_steering() const;
|
||||
void set_brake(bool value);
|
||||
bool get_brake() const;
|
||||
void set_oversteer_curve(Ref<Curve> curve);
|
||||
Ref<Curve> get_oversteer_curve() const;
|
||||
void set_understeer_curve(Ref<Curve> curve);
|
||||
Ref<Curve> get_understeer_curve() const;
|
||||
private:
|
||||
float target_speed{0.f};
|
||||
float current_steering{0.f};
|
||||
Vector3 local_velocity{};
|
||||
float gravity_velocity{-1.f};
|
||||
bool brake{false};
|
||||
Ref<Curve> oversteer_curve{};
|
||||
Ref<Curve> understeer_curve{};
|
||||
|
||||
static const float ACCELERATION;
|
||||
static const float BRAKE_FORCE;
|
||||
static const float UNDERSTEER_SPEED_MUL;
|
||||
|
|
Loading…
Reference in a new issue