nightshade_api/
character.rs1use nightshade::prelude::*;
6
7pub fn is_grounded(world: &World, entity: Entity) -> bool {
9 world
10 .get::<nightshade::plugins::physics::components::CharacterControllerComponent>(entity)
11 .map(|controller| controller.grounded)
12 .unwrap_or(false)
13}
14
15pub fn controller_velocity(world: &World, entity: Entity) -> Vec3 {
17 world
18 .get::<nightshade::plugins::physics::components::CharacterControllerComponent>(entity)
19 .map(|controller| controller.velocity)
20 .unwrap_or_else(Vec3::zeros)
21}
22
23pub fn set_controller_speed(world: &mut World, entity: Entity, speed: f32) {
25 if let Some(controller) = world
26 .get_mut::<nightshade::plugins::physics::components::CharacterControllerComponent>(
27 entity,
28 ) {
29 controller.max_speed = speed;
30 }
31}
32
33pub fn set_controller_jump(world: &mut World, entity: Entity, jump_impulse: f32) {
35 if let Some(controller) = world
36 .get_mut::<nightshade::plugins::physics::components::CharacterControllerComponent>(
37 entity,
38 ) {
39 controller.jump_impulse = jump_impulse;
40 }
41}
42
43pub fn move_character(world: &mut World, entity: Entity, movement: Vec2, jump: bool) {
47 if let Some(controller) = world
48 .get_mut::<nightshade::plugins::physics::components::CharacterControllerComponent>(
49 entity,
50 ) {
51 controller.external_movement = movement;
52 controller.external_jump = jump;
53 }
54}