Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
KinematicCharacterController.h
Go to the documentation of this file.
1/**
2 * @file KinematicCharacterController.h
3 * @ingroup mnd_physics
4 * @brief Capsule-shaped character controller backed by Bullet's
5 * `btKinematicCharacterController`.
6 */
7
8#pragma once
9#include <memory>
10
11#include "Constants.h"
12#include "Types.h"
13#include "physics/CollisionObject.h"
14
15class btPairCachingGhostObject;
16class btKinematicCharacterController;
17
18namespace mnd
19{
20
21/**
22 * @ingroup mnd_physics
23 * @brief High-level capsule character controller: walks, jumps, detects ground.
24 *
25 * Unlike a @ref RigidBody, this object is **not** force-driven. Game code calls
26 * @ref Walk / @ref Jump with desired directions and Bullet resolves the resulting
27 * motion against the collision world.
28 */
30{
31 public:
32 /**
33 * @param radius Capsule radius (metres).
34 * @param height Capsule height (metres, full — caps included).
35 * @param position Initial world position.
36 */
37 KinematicCharacterController(float radius, float height, const glm::vec3 &position);
39
40 [[nodiscard]] vec3 GetPosition() const;
41 [[nodiscard]] quat GetRotation() const;
42
43 /// Apply a walk velocity in world space for this frame.
44 void Walk(const vec3 &direction);
45
46 /// Apply an impulse-style jump in @p direction (typically `{0, jumpSpeed, 0}`).
47 void Jump(const vec3 &direction);
48
49 /// True when the controller has a contact point beneath it.
50 [[nodiscard]] bool OnGround() const;
51
52 private:
53 float m_height = kDefaultCapsuleHeight;
54 float m_radius = kDefaultCapsuleRadius;
55
56 std::unique_ptr<btPairCachingGhostObject> m_ghost;
57 std::unique_ptr<btKinematicCharacterController> m_controller;
58};
59
60} // namespace mnd
Engine-wide compile-time tunables and ANSI colour codes.
constexpr mnd::f32 kDefaultCapsuleRadius
Definition Constants.h:68
constexpr mnd::f32 kDefaultCapsuleHeight
Definition Constants.h:69
Engine-wide primitive type aliases and GLM math imports.
High-level capsule character controller: walks, jumps, detects ground.
void Jump(const vec3 &direction)
Apply an impulse-style jump in direction (typically {0, jumpSpeed, 0}).
void Walk(const vec3 &direction)
Apply a walk velocity in world space for this frame.
bool OnGround() const
True when the controller has a contact point beneath it.
glm::vec3 vec3
3-component float vector (e.g. world position, RGB colour, normals).
Definition Types.h:51
glm::quat quat
Unit quaternion for rotation (avoids gimbal lock).
Definition Types.h:65