logo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use super::*;

/// Physics character component
///
/// Use to get predictable collisions against the physics world for an entity. Suitable for things
/// like FPS shooter characters and other similar things that are directly controlled by the player
/// and would be impractical to get to behave correctly using real physics.
///
/// Puts a capsule around the entity, defined by the height and radius properties, to do collisions.
/// Uses the `Velocity` component to update the position of the entity and leaves adding gravity to that
/// to the user.

#[cfg(target_arch = "wasm32")]
pub struct PhysicsCharacter {
    id: Entity,
}

impl std::fmt::Debug for PhysicsCharacter {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("PhysicsCharacter")
            .field("entity", &self.id.name())
            .finish_non_exhaustive()
    }
}

#[cfg(target_arch = "wasm32")]
impl PhysicsCharacter {
    impl_world_accessor!(
        /// Returns a `ValueAccessor` for the character radius (horizontal plane).
        PhysicsCharacter,
        Radius,
        f32,
        radius,
        ValueAccessorReadWriteAnimate
    );

    impl_world_accessor!(
        /// Returns a `ValueAccessor` for the character vertical height.
        PhysicsCharacter,
        Height,
        f32,
        height,
        ValueAccessorReadWriteAnimate
    );

    impl_world_accessor!(
        /// Returns a `ValueAccessor` for the character up direction.
        PhysicsCharacter,
        UpDirection,
        Vec3,
        up_direction,
        ValueAccessorReadWriteAnimate
    );

    impl_world_accessor!(
        /// Returns a `ValueAccessor` for the character collision flags.
        ///
        /// Use it to see what collisions the last frame resulted in, for instance
        /// to reset velocity if ground was hit. Can only be read.
        PhysicsCharacter,
        CollisionFlags,
        CharacterCollisionFlags,
        collision_flags,
        ValueAccessorRead
    );

    impl_world_accessor!(
        /// Returns a `ValueAccessor` for the world linear velocity of the physics character.
        ///
        /// Used to set/get/animate the velocity.
        PhysicsCharacter,
        Velocity,
        Vec3,
        velocity,
        ValueAccessorReadWriteAnimate
    );
}

impl_world_component!(PhysicsCharacter);