Unravel Engine C++ Reference
Loading...
Searching...
No Matches
character_controller_component.h
Go to the documentation of this file.
1#pragma once
2#include <engine/engine_export.h>
3
6#include <math/math.h>
7
8#include <bitset>
9
10namespace unravel
11{
12
28
36class character_controller_component : public component_crtp<character_controller_component, owned_component>
37{
38public:
44 static void on_create_component(entt::registry& r, entt::entity e);
45
51 static void on_destroy_component(entt::registry& r, entt::entity e);
52
53 void set_radius(float radius);
54 auto get_radius() const noexcept -> float;
55
56 void set_height(float height);
57 auto get_height() const noexcept -> float;
58
59 void set_center(const math::vec3& center);
60 auto get_center() const noexcept -> const math::vec3&;
61
62 void set_step_height(float step_height);
63 auto get_step_height() const noexcept -> float;
64
65 void set_slope_limit(float slope_limit_degrees);
66 auto get_slope_limit() const noexcept -> float;
67
68 void set_skin_width(float skin_width);
69 auto get_skin_width() const noexcept -> float;
70
71 void set_gravity_scale(float scale);
72 auto get_gravity_scale() const noexcept -> float;
73
76
79
80 auto get_collision_mask() const -> layer_mask;
81
82 void move(const math::vec3& displacement);
83
88 void jump(float speed);
89
95 void jump(const math::vec3& velocity);
96
97 void apply_impulse(const math::vec3& impulse);
98 void warp(const math::vec3& position);
99
100 void set_terminal_velocity(float speed);
101 auto get_terminal_velocity() const noexcept -> float;
102
103 void set_linear_velocity(const math::vec3& velocity);
104 auto get_linear_velocity() const noexcept -> math::vec3;
105
106 void set_linear_damping(float damping);
107 auto get_linear_damping() const noexcept -> float;
108
109 auto can_jump() const noexcept -> bool;
110 auto is_grounded() const noexcept -> bool;
111 auto get_velocity() const noexcept -> const math::vec3&;
112
113 auto is_dirty(uint8_t id) const noexcept -> bool;
114 void set_dirty(uint8_t id, bool dirty) noexcept;
115
116 auto is_property_dirty(character_controller_property prop) const noexcept -> bool;
117 auto are_any_properties_dirty() const noexcept -> bool;
118 void set_property_dirty(character_controller_property prop, bool dirty) noexcept;
119
120 void set_grounded(bool grounded) noexcept;
121 void set_velocity_internal(const math::vec3& vel) noexcept;
122
123private:
124 void on_change_shape();
125
126 float radius_{0.5f};
127 float height_{1.0f};
128 math::vec3 center_{};
129 float step_height_{0.3f};
130 float slope_limit_{45.0f};
131 float skin_width_{0.08f};
132 float gravity_scale_{1.0f};
133
134 float terminal_velocity_{55.0f};
135 float linear_damping_{0.0f};
136
137 layer_mask collision_include_mask_{layer_reserved::everything_layer};
138 layer_mask collision_exclude_mask_{layer_reserved::nothing_layer};
139
140 math::vec3 velocity_{};
141 bool grounded_{false};
142
143 using underlying_t = std::underlying_type_t<character_controller_property>;
144 std::bitset<static_cast<underlying_t>(character_controller_property::count)> dirty_properties_;
145 std::bitset<8> dirty_;
146};
147
148} // namespace unravel
uint32_t height
int layer_mask
Component for character controller physics with sweep-based movement.
void set_velocity_internal(const math::vec3 &vel) noexcept
auto get_linear_velocity() const noexcept -> math::vec3
auto is_property_dirty(character_controller_property prop) const noexcept -> bool
static void on_destroy_component(entt::registry &r, entt::entity e)
Called when the component is destroyed.
auto get_velocity() const noexcept -> const math::vec3 &
static void on_create_component(entt::registry &r, entt::entity e)
Called when the component is created.
auto is_dirty(uint8_t id) const noexcept -> bool
auto get_center() const noexcept -> const math::vec3 &
void jump(float speed)
Trigger a jump straight up with the given speed (m/s).
void set_property_dirty(character_controller_property prop, bool dirty) noexcept
math::vec3 position
Definition defaults.cpp:52
@ everything_layer
Definition layer_mask.h:16
@ nothing_layer
Definition layer_mask.h:13
@ mask
Hard alpha cutoff; casts cutout shadows.
character_controller_property
Enum for trackable character controller properties.
std::vector< float > scale
CRTP (Curiously Recurring Template Pattern) base structure for components.