Unravel Engine C++ Reference
Loading...
Searching...
No Matches
character_controller_component.cpp
Go to the documentation of this file.
4
7
8namespace unravel
9{
10
12{
13 entt::meta_factory<character_controller_component>{}
14 .type("character_controller_component"_hs)
16 entt::attribute{"name", "character_controller_component"},
17 entt::attribute{"category", "PHYSICS"},
18 entt::attribute{"pretty_name", "Character Controller"},
19 })
26 .custom<entt::attributes>(entt::attributes{
27 entt::attribute{"name", "radius"},
28 entt::attribute{"pretty_name", "Radius"},
29 entt::attribute{"tooltip", "The radius of the character capsule."},
30 entt::attribute{"min", 0.01f},
31 entt::attribute{"step", 0.1f},
32 })
33 .data<&character_controller_component::set_height, &character_controller_component::get_height>("height"_hs)
35 entt::attribute{"name", "height"},
36 entt::attribute{"pretty_name", "Height"},
37 entt::attribute{"tooltip", "The total height of the character capsule."},
38 entt::attribute{"min", 0.01f},
39 entt::attribute{"step", 0.1f},
40 })
41 .data<&character_controller_component::set_center, &character_controller_component::get_center>("center"_hs)
43 entt::attribute{"name", "center"},
44 entt::attribute{"pretty_name", "Center"},
45 entt::attribute{"tooltip", "The center offset of the capsule relative to the entity transform."},
46 })
47 .data<&character_controller_component::set_step_height, &character_controller_component::get_step_height>("step_height"_hs)
49 entt::attribute{"name", "step_height"},
50 entt::attribute{"pretty_name", "Step Offset"},
51 entt::attribute{"tooltip", "Maximum height of obstacles the character can step over."},
52 entt::attribute{"min", 0.0f},
53 entt::attribute{"step", 0.05f},
54 })
55 .data<&character_controller_component::set_slope_limit, &character_controller_component::get_slope_limit>("slope_limit"_hs)
57 entt::attribute{"name", "slope_limit"},
58 entt::attribute{"pretty_name", "Slope Limit"},
59 entt::attribute{"tooltip", "Maximum slope angle in degrees the character can walk up."},
60 entt::attribute{"min", 0.0f},
61 entt::attribute{"max", 90.0f},
62 entt::attribute{"step", 1.0f},
63 })
64 .data<&character_controller_component::set_skin_width, &character_controller_component::get_skin_width>("skin_width"_hs)
66 entt::attribute{"name", "skin_width"},
67 entt::attribute{"pretty_name", "Skin Width"},
68 entt::attribute{"tooltip", "Collision skin width around the character capsule."},
69 entt::attribute{"min", 0.001f},
70 entt::attribute{"step", 0.01f},
71 })
72 .data<&character_controller_component::set_gravity_scale, &character_controller_component::get_gravity_scale>("gravity_scale"_hs)
74 entt::attribute{"name", "gravity_scale"},
75 entt::attribute{"pretty_name", "Gravity Scale"},
76 entt::attribute{"tooltip", "Multiplier for world gravity applied to this controller."},
77 entt::attribute{"step", 0.1f},
78 })
79 .data<&character_controller_component::set_collision_include_mask, &character_controller_component::get_collision_include_mask>("include_layers"_hs)
81 entt::attribute{"name", "include_layers"},
82 entt::attribute{"pretty_name", "Include Layers"},
83 entt::attribute{"tooltip", "Layers to include when producing collisions."},
84 })
85 .data<&character_controller_component::set_collision_exclude_mask, &character_controller_component::get_collision_exclude_mask>("exclude_layers"_hs)
87 entt::attribute{"name", "exclude_layers"},
88 entt::attribute{"pretty_name", "Exclude Layers"},
89 entt::attribute{"tooltip", "Layers to exclude when producing collisions."},
90 })
91 .data<nullptr, &character_controller_component::get_collision_mask>("collision_layers"_hs)
93 entt::attribute{"name", "collision_layers"},
94 entt::attribute{"pretty_name", "Collision Layers"},
95 entt::attribute{"tooltip", "Layers (Include - Exclude) used when producing collisions."},
96 })
97 .data<&character_controller_component::set_terminal_velocity, &character_controller_component::get_terminal_velocity>("terminal_velocity"_hs)
99 entt::attribute{"name", "terminal_velocity"},
100 entt::attribute{"pretty_name", "Terminal Velocity"},
101 entt::attribute{"tooltip", "Maximum downward fall speed in m/s. Default 55 (skydiver terminal velocity)."},
102 entt::attribute{"min", 0.0f},
103 entt::attribute{"step", 1.0f},
104 })
105 .data<&character_controller_component::set_linear_damping, &character_controller_component::get_linear_damping>("linear_damping"_hs)
107 entt::attribute{"name", "linear_damping"},
108 entt::attribute{"pretty_name", "Linear Damping"},
109 entt::attribute{"tooltip", "Damping applied to linear velocity each step. 0 = no damping, 1 = full damping."},
110 entt::attribute{"min", 0.0f},
111 entt::attribute{"max", 1.0f},
112 entt::attribute{"step", 0.05f},
113 })
114 .data<nullptr, &character_controller_component::is_grounded>("is_grounded"_hs)
116 entt::attribute{"name", "is_grounded"},
117 entt::attribute{"pretty_name", "Is Grounded"},
118 })
119 .data<nullptr, &character_controller_component::can_jump>("can_jump"_hs)
121 entt::attribute{"name", "can_jump"},
122 entt::attribute{"pretty_name", "Can Jump"},
123 })
124 .data<nullptr, &character_controller_component::get_velocity>("velocity"_hs)
126 entt::attribute{"name", "velocity"},
127 entt::attribute{"pretty_name", "Velocity"},
128 });
129}
130
132{
133 try_save(ar, ser20::make_nvp("radius", obj.get_radius()));
134 try_save(ar, ser20::make_nvp("height", obj.get_height()));
135 try_save(ar, ser20::make_nvp("center", obj.get_center()));
136 try_save(ar, ser20::make_nvp("step_height", obj.get_step_height()));
137 try_save(ar, ser20::make_nvp("slope_limit", obj.get_slope_limit()));
138 try_save(ar, ser20::make_nvp("skin_width", obj.get_skin_width()));
139 try_save(ar, ser20::make_nvp("gravity_scale", obj.get_gravity_scale()));
140 try_save(ar, ser20::make_nvp("include_layers", obj.get_collision_include_mask()));
141 try_save(ar, ser20::make_nvp("exclude_layers", obj.get_collision_exclude_mask()));
142 try_save(ar, ser20::make_nvp("terminal_velocity", obj.get_terminal_velocity()));
143 try_save(ar, ser20::make_nvp("linear_damping", obj.get_linear_damping()));
144}
147
149{
150 float radius{0.5f};
151 if(try_load(ar, ser20::make_nvp("radius", radius)))
152 {
153 obj.set_radius(radius);
154 }
155 float height{2.0f};
156 if(try_load(ar, ser20::make_nvp("height", height)))
157 {
158 obj.set_height(height);
159 }
160 math::vec3 center{};
161 if(try_load(ar, ser20::make_nvp("center", center)))
162 {
163 obj.set_center(center);
164 }
165 float step_height{0.3f};
166 if(try_load(ar, ser20::make_nvp("step_height", step_height)))
167 {
168 obj.set_step_height(step_height);
169 }
170 float slope_limit{45.0f};
171 if(try_load(ar, ser20::make_nvp("slope_limit", slope_limit)))
172 {
173 obj.set_slope_limit(slope_limit);
174 }
175 float skin_width{0.08f};
176 if(try_load(ar, ser20::make_nvp("skin_width", skin_width)))
177 {
178 obj.set_skin_width(skin_width);
179 }
180 float gravity_scale{1.0f};
181 if(try_load(ar, ser20::make_nvp("gravity_scale", gravity_scale)))
182 {
183 obj.set_gravity_scale(gravity_scale);
184 }
185 layer_mask include_layers;
186 if(try_load(ar, ser20::make_nvp("include_layers", include_layers)))
187 {
188 obj.set_collision_include_mask(include_layers);
189 }
190 layer_mask exclude_layers;
191 if(try_load(ar, ser20::make_nvp("exclude_layers", exclude_layers)))
192 {
193 obj.set_collision_exclude_mask(exclude_layers);
194 }
195 float terminal_velocity{55.0f};
196 if(try_load(ar, ser20::make_nvp("terminal_velocity", terminal_velocity)) ||
197 try_load(ar, ser20::make_nvp("fall_speed", terminal_velocity)))
198 {
199 obj.set_terminal_velocity(terminal_velocity);
200 }
201 float linear_damping{0.0f};
202 if(try_load(ar, ser20::make_nvp("linear_damping", linear_damping)))
203 {
204 obj.set_linear_damping(linear_damping);
205 }
206}
207
210
211} // namespace unravel
uint32_t height
Component for character controller physics with sweep-based movement.
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
BinaryInputArchive iarchive_binary_t
simd::JSONOutputArchive oarchive_associative_t
BinaryOutputArchive oarchive_binary_t
simd::JSONInputArchive iarchive_associative_t
#define REFLECT(cls)
Definition reflection.h:149
#define SAVE_INSTANTIATE(cls, Archive)
#define LOAD(cls)
auto try_save(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
#define LOAD_INSTANTIATE(cls, Archive)
#define SAVE(cls)
auto try_load(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool