Fix the aiming and bullet creation

This commit is contained in:
2025-02-01 18:03:00 +01:00
parent 33f1d57a50
commit bd91818682
19 changed files with 334 additions and 8089 deletions

View File

@ -8,7 +8,6 @@ struct PlayerServerNode {
base: Base<CharacterBody3D>,
jumping: bool,
input_direction: Vector2,
input_rotation: Vector3,
}
const JUMP_VELOCITY: f32 = 4.5;
@ -21,7 +20,6 @@ impl ICharacterBody3D for PlayerServerNode {
base,
jumping: false,
input_direction: Vector2::new(0.0, 0.0),
input_rotation: Vector3::new(0.0, 0.0, 0.0),
}
}
@ -40,7 +38,7 @@ impl ICharacterBody3D for PlayerServerNode {
self.base_mut().set_velocity(new_velocity);
}
self.jumping = false;
if self.base().is_on_floor() {
let direction = self.base().get_transform().basis
* Vector3::new(self.input_direction.x, 0.0, self.input_direction.y);
@ -79,17 +77,33 @@ impl PlayerServerNode {
self.input_direction = new_input_direction;
}
#[rpc(any_peer, call_local, unreliable_ordered)]
fn set_rotation_x(&mut self, x: f32) {
let mut new_rotation = self.base().get_rotation();
new_rotation.x = x;
self.base_mut().set_rotation(new_rotation);
}
#[rpc(any_peer, call_local, unreliable_ordered)]
fn set_rotation_y(&mut self, y: f32) {
let mut new_rotation = self.base().get_rotation();
new_rotation.y = y;
self.base_mut().set_rotation(new_rotation);
}
#[rpc(any_peer, call_local, unreliable_ordered)]
fn set_rotation_x(&mut self, x: f32) {
let mut camera_mount = self.base().get_node_as::<Node3D>("BulletStartingPoint");
let mut new_rotation = camera_mount.get_rotation();
new_rotation.x = x;
camera_mount.set_rotation(new_rotation);
}
#[rpc(any_peer, call_local, unreliable_ordered)]
fn shoot(&mut self) {
let bullet_starting_poing = match self.base().find_child("BulletStartingPoint") {
Some(node) => node,
None => return,
};
let casted_bullet_node = bullet_starting_poing.cast::<Node3D>();
let mut map = match self.base().find_parent("Map") {
Some(map) => map,
None => return,
};
let args = &[casted_bullet_node.to_variant(), 10.to_variant(), 10.to_variant()];
map.call("spawn_bullet", args);
}
}