Player System
Source: client/engine/systems/SystemsFunctions/PlayerSystem.cpp
Purpose: Update player animation based on vertical velocity and sync rotation of the player and its children based on horizontal velocity.
Components used:
PlayerTag(containsspeed_maxand other player properties)Velocity(readsvxandvy)AnimatedSprite(updatescurrent_frame)Transform(updatesrotationDegreesfor player and children)
Behavior
Vertical animation
animated_sprite.current_frame is set according to vertical velocity (velocity.vy):
| Condition | Frame | Animation |
|---|---|---|
vy > 200.f | 0 | Fast downward |
vy >= 75 | 1 | Moderate downward |
vy < -200.f | 4 | Fast upward |
vy <= -75 | 3 | Moderate upward |
| Else | 2 | Neutral |
Horizontal rotation
The system computes a rotation angle based on horizontal velocity:
float rotation = velocity.vx / player_tag.speed_max * 5.f;
transform.rotationDegrees = rotation;
This gives a tilt proportional to horizontal speed.
Child sync
Rotation propagates to all child entities:
for (auto &&[j, child_transform] : make_indexed_zipper(transforms)) {
if (child_transform.parent_entity.has_value() &&
child_transform.parent_entity.value() == i) {
child_transform.rotationDegrees = rotation;
}
}
Child assets (e.g., the charge effect) follow the same tilt.
Main signature
void PlayerSystem(Eng::registry ®,
Eng::sparse_array<Com::PlayerTag> const &player_tags,
Eng::sparse_array<Com::Velocity> const &velocities,
Eng::sparse_array<Com::Transform> &transforms,
Eng::sparse_array<Com::AnimatedSprite> &animated_sprites);
Notes
- Animation thresholds (200.f, 75) are hard-coded in current logic.
- The rotation factor (5.f) sets the max tilt amplitude.
- This system does not apply physics; it only syncs visuals to velocity.
- Child lookup scans all transforms; could be optimized with
Transform.children(likeChargingShowAssetPlayerSystem).
Possible improvements
- Optimization: Use
transform.childreninstead of scanning all transforms for children. - Configuration: Externalize animation thresholds and rotation factor into constants or
PlayerTag. - Interpolation: Smoothly transition between animation frames.
- Vertical rotation: Add slight pitch based on
vyfor more dynamism.