Skip to main content

gizmo_physics_core/components/
hitbox.rs

1use gizmo_math::Vec3;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Debug, Serialize, Deserialize)]
6pub struct Hitbox {
7    pub offset: Vec3,
8    pub half_extents: Vec3,
9    pub damage: f32,
10    pub active: bool,
11}
12
13impl Default for Hitbox {
14    fn default() -> Self {
15        Self {
16            offset: Vec3::ZERO,
17            half_extents: Vec3::new(0.2, 0.2, 0.2),
18            damage: 10.0,
19            active: true,
20        }
21    }
22}
23
24impl Hitbox {
25    pub fn new(half_extents: Vec3, damage: f32) -> Self {
26        Self {
27            offset: Vec3::ZERO,
28            half_extents,
29            damage,
30            active: true,
31        }
32    }
33}
34
35#[derive(Clone, Debug, Serialize, Deserialize)]
36pub struct Hurtbox {
37    pub offset: Vec3,
38    pub half_extents: Vec3,
39    pub damage_multiplier: f32,
40}
41
42impl Default for Hurtbox {
43    fn default() -> Self {
44        Self {
45            offset: Vec3::ZERO,
46            half_extents: Vec3::new(0.3, 0.5, 0.3),
47            damage_multiplier: 1.0,
48        }
49    }
50}
51
52impl Hurtbox {
53    pub fn new(half_extents: Vec3) -> Self {
54        Self {
55            offset: Vec3::ZERO,
56            half_extents,
57            damage_multiplier: 1.0,
58        }
59    }
60}
61
62gizmo_core::impl_component!(Hitbox);
63gizmo_core::impl_component!(Hurtbox);