Add some rotation to shooting animation
This commit is contained in:
parent
cae47f86ed
commit
9d78db008d
@ -305,14 +305,19 @@ impl IPlayer for LocalPlayer {
|
||||
if let Some(mut weapon) = self.get_weapon()
|
||||
&& let Some(camera_origin) = &self.camera_origin
|
||||
{
|
||||
weapon.dyn_bind_mut().shoot(
|
||||
if weapon.dyn_bind_mut().shoot(
|
||||
rid,
|
||||
self.player_id.unwrap_or(0),
|
||||
camera_origin.get_global_position(),
|
||||
to,
|
||||
camera_origin.get_global_basis().col_b(),
|
||||
deal_damage,
|
||||
)
|
||||
) {
|
||||
weapon.set_rotation(Vector3::RIGHT * 0.3);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
@ -551,6 +556,13 @@ impl ICharacterBody3D for LocalPlayer {
|
||||
} else {
|
||||
(0., 0.)
|
||||
};
|
||||
let done_cd_percent =
|
||||
1. - (weapon.dyn_bind().get_remaining_cd() / weapon.dyn_bind().get_max_cd());
|
||||
let new_weapon_rot = weapon
|
||||
.get_rotation()
|
||||
.lerp(Vector3::ZERO, 0.03 * done_cd_percent as f32);
|
||||
weapon.set_rotation(new_weapon_rot);
|
||||
|
||||
let prev_weapon_pos = weapon.get_position();
|
||||
let new_y = prev_weapon_pos.y.lerp(target_y as f32, 0.2);
|
||||
let new_x = prev_weapon_pos.x.lerp(target_x as f32, 0.2);
|
||||
|
||||
@ -23,6 +23,7 @@ pub trait Weapon {
|
||||
deal_damage: bool,
|
||||
) -> bool;
|
||||
fn get_type(&self) -> WeaponType;
|
||||
fn get_max_cd(&self) -> f64;
|
||||
fn get_remaining_cd(&self) -> f64;
|
||||
fn set_remaining_cd(&mut self, cd: f64);
|
||||
}
|
||||
@ -130,6 +131,10 @@ impl Weapon for Raygun {
|
||||
WeaponType::Raygun
|
||||
}
|
||||
|
||||
fn get_max_cd(&self) -> f64 {
|
||||
self.cooldown
|
||||
}
|
||||
|
||||
fn get_remaining_cd(&self) -> f64 {
|
||||
self.cooldown_remaining
|
||||
}
|
||||
@ -230,6 +235,10 @@ impl Weapon for Shotgun {
|
||||
WeaponType::Shotgun
|
||||
}
|
||||
|
||||
fn get_max_cd(&self) -> f64 {
|
||||
self.cooldown
|
||||
}
|
||||
|
||||
fn get_remaining_cd(&self) -> f64 {
|
||||
self.cooldown_remaining
|
||||
}
|
||||
@ -299,6 +308,10 @@ impl Weapon for BallWeapon {
|
||||
WeaponType::Ball
|
||||
}
|
||||
|
||||
fn get_max_cd(&self) -> f64 {
|
||||
0.
|
||||
}
|
||||
|
||||
fn get_remaining_cd(&self) -> f64 {
|
||||
0.
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user