Unravel Engine C++ Reference
Loading...
Searching...
No Matches
character_controller_component.cpp
Go to the documentation of this file.
3
4namespace unravel
5{
6
7void character_controller_component::on_create_component(entt::registry& r, entt::entity e)
8{
9 entt::handle entity(r, e);
10 auto& component = entity.get<character_controller_component>();
11 component.set_owner(entity);
12 component.dirty_.set();
13 component.dirty_properties_.set();
14}
15
16void character_controller_component::on_destroy_component(entt::registry& r, entt::entity e)
17{
18}
19
21{
22 if(math::epsilonEqual(radius_, radius, math::epsilon<float>()))
23 {
24 return;
25 }
26 radius_ = radius;
27 on_change_shape();
28}
29
30auto character_controller_component::get_radius() const noexcept -> float
31{
32 return radius_;
33}
34
36{
37 if(math::epsilonEqual(height_, height, math::epsilon<float>()))
38 {
39 return;
40 }
41 height_ = height;
42 on_change_shape();
43}
44
45auto character_controller_component::get_height() const noexcept -> float
46{
47 return height_;
48}
49
51{
52 if(center_ == center)
53 {
54 return;
55 }
56 center_ = center;
57 on_change_shape();
58}
59
60auto character_controller_component::get_center() const noexcept -> const math::vec3&
61{
62 return center_;
63}
64
66{
67 if(math::epsilonEqual(step_height_, step_height, math::epsilon<float>()))
68 {
69 return;
70 }
71 step_height_ = step_height;
72 dirty_.set();
74}
75
77{
78 return step_height_;
79}
80
82{
83 if(math::epsilonEqual(slope_limit_, slope_limit_degrees, math::epsilon<float>()))
84 {
85 return;
86 }
87 slope_limit_ = slope_limit_degrees;
88 dirty_.set();
90}
91
93{
94 return slope_limit_;
95}
96
98{
99 if(math::epsilonEqual(skin_width_, skin_width, math::epsilon<float>()))
100 {
101 return;
102 }
103 skin_width_ = skin_width;
104 dirty_.set();
106}
107
109{
110 return skin_width_;
111}
112
114{
115 if(math::epsilonEqual(gravity_scale_, scale, math::epsilon<float>()))
116 {
117 return;
118 }
119 gravity_scale_ = scale;
120 dirty_.set();
122}
123
125{
126 return gravity_scale_;
127}
128
135
137{
138 return collision_include_mask_;
139}
140
147
149{
150 return collision_exclude_mask_;
151}
152
154{
155 return layer_mask{collision_include_mask_.mask & ~collision_exclude_mask_.mask};
156}
157
158void character_controller_component::move(const math::vec3& displacement)
159{
160 physics_system::move_character(*this, displacement);
161}
162
164{
165 physics_system::jump_character(*this, math::vec3{0.0f, speed, 0.0f});
166}
167
172
177
182
184{
185 if(math::epsilonEqual(terminal_velocity_, speed, math::epsilon<float>()))
186 {
187 return;
188 }
189 terminal_velocity_ = speed;
190 dirty_.set();
192}
193
195{
196 return terminal_velocity_;
197}
198
203
205{
206 return velocity_;
207}
208
210{
211 if(math::epsilonEqual(linear_damping_, damping, math::epsilon<float>()))
212 {
213 return;
214 }
215 linear_damping_ = damping;
216 dirty_.set();
218}
219
221{
222 return linear_damping_;
223}
224
225auto character_controller_component::can_jump() const noexcept -> bool
226{
227 return grounded_;
228}
229
231{
232 return grounded_;
233}
234
235auto character_controller_component::get_velocity() const noexcept -> const math::vec3&
236{
237 return velocity_;
238}
239
241{
242 grounded_ = grounded;
243}
244
246{
247 velocity_ = vel;
248}
249
250auto character_controller_component::is_dirty(uint8_t id) const noexcept -> bool
251{
252 return dirty_[id];
253}
254
255void character_controller_component::set_dirty(uint8_t id, bool dirty) noexcept
256{
257 dirty_.set(id, dirty);
258 if(!dirty)
259 {
260 dirty_properties_ = {};
261 }
262}
263
265{
266 return dirty_properties_[static_cast<underlying_t>(prop)];
267}
268
270{
271 return dirty_properties_.any();
272}
273
275{
276 dirty_properties_[static_cast<underlying_t>(prop)] = dirty;
277}
278
279void character_controller_component::on_change_shape()
280{
281 dirty_.set();
283}
284
285} // namespace unravel
uint32_t height
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
void set_owner(entt::handle owner)
Sets the owner of the component.
static void jump_character(character_controller_component &comp, const math::vec3 &direction)
static void warp_character(character_controller_component &comp, const math::vec3 &position)
static void apply_impulse_character(character_controller_component &comp, const math::vec3 &impulse)
static void move_character(character_controller_component &comp, const math::vec3 &displacement)
Moves a character controller by a displacement.
static void set_character_linear_velocity(character_controller_component &comp, const math::vec3 &velocity)
const char * id
math::vec3 position
Definition defaults.cpp:52
Definition bbox.cpp:5
@ mask
Hard alpha cutoff; casts cutout shadows.
character_controller_property
Enum for trackable character controller properties.
std::vector< float > scale
entt::handle entity