feat: add interactable component and test button

This commit is contained in:
2026-10-16 23:25:11 +02:00
parent faba4171ec
commit 7dd5ee7903
14 changed files with 236 additions and 6 deletions
@@ -7,9 +7,8 @@
class Rigidbody;
class CapsuleCollider;
class Interactable;
// Dynamic capsule character. Velocity is driven directly (no forces) so movement stays responsive:
// acceleration towards the wished velocity, own gravity, coyote time and jump buffering.
class FirstPersonController final : public Component {
public:
explicit FirstPersonController(GameObject& parent);
@@ -26,9 +25,9 @@ public:
[[nodiscard]] float GetYaw() const { return m_Yaw; }
void SetYaw(float yawRadians) { m_Yaw = yawRadians; }
[[nodiscard]] float GetPitch() const { return m_Pitch; }
void SetPitch(float pitchRadians) { m_Pitch = pitchRadians; }
[[nodiscard]] float GetEyeHeight() const { return m_EyeHeight; }
// Eye position interpolated between the last two physics steps, so the camera moves smoothly at any framerate
[[nodiscard]] glm::vec3 GetEyePosition() const;
void SetMovementSpeed(float speed) { m_WalkSpeed = speed; }
@@ -39,12 +38,16 @@ public:
[[nodiscard]] bool IsGrounded() const { return m_Grounded; }
[[nodiscard]] Interactable* GetFocusedInteractable() const { return m_FocusedInteractable; }
[[nodiscard]] glm::vec3 GetLookDirection() const;
[[nodiscard]] bool IsMouseCaptured() const { return InputManager::GetInstance().IsMouseCaptured(); }
void SetMouseCaptured(bool captured);
private:
[[nodiscard]] bool CheckGrounded() const;
[[nodiscard]] glm::vec3 GetWishDirection() const;
[[nodiscard]] Interactable* FindFocusedInteractable() const;
Rigidbody* m_Rigidbody{nullptr};
CapsuleCollider* m_Capsule{nullptr};
@@ -63,6 +66,9 @@ private:
float m_FallGravityMultiplier{1.6f};
float m_CoyoteTime{0.1f};
float m_JumpBufferTime{0.12f};
float m_InteractDistance{3.0f};
Interactable* m_FocusedInteractable{nullptr};
bool m_Grounded{false};
bool m_JumpHeld{false};