feat: improved camera auto-rotate

This commit is contained in:
Sara Gerretsen 2026-05-14 23:13:06 +02:00
parent 5d110598cd
commit 50f86cb2ba
2 changed files with 5 additions and 2 deletions

View file

@ -12,6 +12,7 @@
void PlayerCamera::_bind_methods() {
BIND_PROPERTY(Variant::FLOAT, target_distance);
BIND_HPROPERTY(Variant::INT, blocking_mask, PROPERTY_HINT_LAYERS_3D_PHYSICS);
BIND_PROPERTY(Variant::VECTOR2, auto_righting);
}
void PlayerCamera::update_rotation() {
@ -22,7 +23,7 @@ void PlayerCamera::update_rotation() {
forward.y = 0;
float const x_difference{ forward.signed_angle_to(Vector3{ velocity.x, 0, velocity.z }.normalized(), Vector3::UP) };
this->global_rotate(Vector3::UP, CLAMP(Math::pow(x_difference, 3.f), -2.f, 2.f) * delta);
this->global_rotate(Vector3::UP, CLAMP(Math::pow(x_difference, 3.f), -auto_righting.x, auto_righting.x) * delta);
forward = -get_global_basis().get_column(2).normalized();
forward = Vector3(velocity.x, forward.y, velocity.z).normalized();
@ -30,7 +31,7 @@ void PlayerCamera::update_rotation() {
left.y = 0.f;
float const y_difference{ forward.signed_angle_to(velocity.normalized(), left.normalized()) };
this->rotate_object_local(Vector3::RIGHT, CLAMP(Math::pow(y_difference, 3.f), -2.f, 2.f) * delta);
this->rotate_object_local(Vector3::RIGHT, CLAMP(Math::pow(y_difference, 3.f), -auto_righting.y, auto_righting.y) * delta);
}
this->mouse_look_input *= 0.0001f;
this->rotate(Vector3::DOWN, this->mouse_look_input.x * this->mouse_sensitivity - this->joystick_input.x * delta * this->joystick_sensitivity);

View file

@ -18,6 +18,7 @@ private:
float target_distance{ 5.f };
float mouse_sensitivity{ 16.f };
float joystick_sensitivity{ 3.f };
Vector2 auto_righting{ 6, 4 };
Vector2 mouse_look_input{};
Vector2 joystick_input{};
@ -39,6 +40,7 @@ public:
GET_SET_FNS(float, target_distance);
GET_SET_FNS(float, mouse_sensitivity);
GET_SET_FNS(float, joystick_sensitivity);
GET_SET_FNS(Vector2, auto_righting);
void set_blocking_mask(uint32_t mask);
uint32_t get_blocking_mask() const;
};