Remove hands from local player, add proper gun_node
This commit is contained in:
parent
d1282693da
commit
f750f2843c
@ -8,7 +8,7 @@ glow_enabled = true
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_oh8vq"]
|
||||
|
||||
[node name="player" type="LocalPlayer" unique_id=863055906 node_paths=PackedStringArray("camera", "soldier_mesh", "collider", "splorch", "dead_cam_target", "respawn_label", "ball_origin")]
|
||||
[node name="player" type="LocalPlayer" unique_id=863055906 node_paths=PackedStringArray("camera", "soldier_mesh", "collider", "splorch", "dead_cam_target", "respawn_label", "ball_origin", "weapon_node")]
|
||||
look_sensitivity = 1.5
|
||||
camera = NodePath("camera_3d")
|
||||
move_speed = 5.0
|
||||
@ -18,6 +18,7 @@ splorch = NodePath("splorch")
|
||||
dead_cam_target = NodePath("dead_camera_target")
|
||||
respawn_label = NodePath("respawn_label")
|
||||
ball_origin = NodePath("camera_3d")
|
||||
weapon_node = NodePath("camera_3d/weapon_node")
|
||||
health = 100
|
||||
collision_mask = 4
|
||||
|
||||
@ -27,6 +28,9 @@ environment = SubResource("Environment_3nx84")
|
||||
current = true
|
||||
fov = 90.0
|
||||
|
||||
[node name="weapon_node" type="Node3D" parent="camera_3d" unique_id=919330414]
|
||||
transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0.09660053, -0.1177212, -0.048912734)
|
||||
|
||||
[node name="soldier_m" parent="." unique_id=281995630 instance=ExtResource("1_jd651")]
|
||||
transform = Transform3D(-0.5, 0, -4.371139e-08, 0, 0.5, 0, 4.371139e-08, 0, -0.5, 0.15878421, 0, 0.19227558)
|
||||
|
||||
|
||||
@ -44,23 +44,24 @@ nodes/Movement/node = SubResource("AnimationNodeBlendSpace2D_tt88r")
|
||||
nodes/Movement/position = Vector2(350, 90)
|
||||
node_connections = [&"output", 0, &"Movement"]
|
||||
|
||||
[node name="soldier_m" type="SoldierMesh" unique_id=281995630 node_paths=PackedStringArray("hand_attachment", "animation_tree", "skeleton", "look_at")]
|
||||
[node name="soldier_m" type="SoldierMesh" unique_id=281995630 node_paths=PackedStringArray("hand_attachment", "animation_tree", "skeleton", "look_at", "hand_remover")]
|
||||
hand_attachment = NodePath("bone_attachment_3d/hand")
|
||||
animation_tree = NodePath("animation_tree")
|
||||
skeleton = NodePath("SoldierM/Soldier/Skeleton3D")
|
||||
raygun = ExtResource("1_a50o4")
|
||||
ball = ExtResource("2_jbny0")
|
||||
look_at = NodePath("look_at_root")
|
||||
hand_remover = NodePath("SoldierM/Soldier/Skeleton3D/player_hand_remover")
|
||||
|
||||
[node name="SoldierM" parent="." unique_id=1868587353 instance=ExtResource("1_sxefq")]
|
||||
|
||||
[node name="Skeleton3D" parent="SoldierM/Soldier" parent_id_path=PackedInt32Array(1868587353, 803584260) index="0" unique_id=1574145981]
|
||||
bones/0/position = Vector3(0, 0, 0.00071418716)
|
||||
bones/1/position = Vector3(0, 0, -0.007)
|
||||
bones/1/rotation = Quaternion(0.69402224, 0, 0, 0.7199537)
|
||||
bones/1/rotation = Quaternion(0.6942035, 0, 0, 0.7197788)
|
||||
bones/1/scale = Vector3(1, 1, 1)
|
||||
bones/2/position = Vector3(0.002, 3.469447e-18, -1.4901118e-10)
|
||||
bones/2/rotation = Quaternion(0.9458209, 2.1373747e-08, 2.3266757e-08, -0.3246889)
|
||||
bones/2/rotation = Quaternion(0.9459847, 2.1362002e-08, 2.3277545e-08, -0.3242114)
|
||||
bones/2/scale = Vector3(1, 1, 1)
|
||||
bones/3/position = Vector3(0, 0.0069999984, 5.169879e-25)
|
||||
bones/3/scale = Vector3(1, 0.99999994, 1)
|
||||
@ -68,7 +69,7 @@ bones/4/position = Vector3(-2.39752e-11, 0.010049875, -1.4156722e-10)
|
||||
bones/4/rotation = Quaternion(0.73982674, -2.6881349e-08, 7.0005948e-09, 0.67279744)
|
||||
bones/4/scale = Vector3(1, 0.99999994, 0.99999994)
|
||||
bones/6/position = Vector3(-0.002, 3.469447e-18, -1.4901205e-10)
|
||||
bones/6/rotation = Quaternion(0.9996778, 1.8178714e-08, 1.8650622e-08, 0.025387304)
|
||||
bones/6/rotation = Quaternion(0.9995959, 1.81219e-08, 1.8705832e-08, 0.02842787)
|
||||
bones/6/scale = Vector3(1, 1, 1)
|
||||
bones/7/position = Vector3(0, 0.0069999984, -5.169879e-25)
|
||||
bones/7/rotation = Quaternion(-0.21973656, 4.264305e-08, 9.604991e-09, 0.9755593)
|
||||
@ -77,33 +78,33 @@ bones/8/position = Vector3(-2.3975525e-11, 0.010049875, -4.6138777e-11)
|
||||
bones/8/rotation = Quaternion(0.86758894, -7.867721e-09, 3.036851e-08, 0.4972821)
|
||||
bones/8/scale = Vector3(1, 0.99999994, 0.99999994)
|
||||
bones/10/position = Vector3(0, 0.009, 0)
|
||||
bones/10/rotation = Quaternion(-0.15427561, -0.13167602, 0.019766005, 0.97901475)
|
||||
bones/10/rotation = Quaternion(-0.1543622, -0.13157132, 0.01979417, 0.97901464)
|
||||
bones/10/scale = Vector3(1, 1, 1)
|
||||
bones/11/position = Vector3(6.8186457e-17, 0.008, 0.001)
|
||||
bones/11/rotation = Quaternion(0.058245, 0.0001169397, -0.01593934, 0.99817514)
|
||||
bones/11/rotation = Quaternion(0.058568474, 0.00011758354, -0.016027864, 0.9981548)
|
||||
bones/11/scale = Vector3(1, 1, 1)
|
||||
bones/12/position = Vector3(-2.2285185e-16, 0.0035, 0.0015000002)
|
||||
bones/12/rotation = Quaternion(-0.70710677, 0, 0, 0.70710677)
|
||||
bones/12/scale = Vector3(1, 1, 1)
|
||||
bones/14/position = Vector3(0.005, 0.005, -1.7336413e-21)
|
||||
bones/14/rotation = Quaternion(0.8948131, 0.033457648, 0.43200484, -0.10752621)
|
||||
bones/14/rotation = Quaternion(0.8948624, 0.033474486, 0.43199828, -0.10713685)
|
||||
bones/14/scale = Vector3(1, 0.99999994, 1)
|
||||
bones/15/position = Vector3(-1.3005262e-15, 0.0050000004, -6.938894e-18)
|
||||
bones/15/rotation = Quaternion(1.035401e-08, -6.774687e-09, 0.93067807, 0.3658392)
|
||||
bones/15/rotation = Quaternion(1.0353366e-08, -6.775671e-09, 0.9306435, 0.3659275)
|
||||
bones/15/scale = Vector3(1, 1, 1)
|
||||
bones/16/position = Vector3(7.632945e-11, 0.007071071, 6.938894e-18)
|
||||
bones/16/rotation = Quaternion(0.0062737567, -0.0943689, -0.18486792, 0.978202)
|
||||
bones/16/rotation = Quaternion(0.0061545833, -0.0946999, -0.18472542, 0.9781977)
|
||||
bones/16/scale = Vector3(0.99999994, 0.9999999, 1)
|
||||
bones/18/position = Vector3(-0.005, 0.005, -1.7303326e-21)
|
||||
bones/18/rotation = Quaternion(0.6564217, 0.1684678, -0.13023898, -0.7237176)
|
||||
bones/18/rotation = Quaternion(0.6569365, 0.16839267, -0.13031884, -0.72325325)
|
||||
bones/18/scale = Vector3(1, 0.99999994, 1)
|
||||
bones/19/position = Vector3(-1.3005262e-15, 0.0050000004, -6.938894e-18)
|
||||
bones/19/rotation = Quaternion(-2.1246766e-08, -3.5550773e-08, -0.26809898, 0.9633914)
|
||||
bones/19/rotation = Quaternion(-2.1264423e-08, -3.5540214e-08, -0.2685776, 0.9632581)
|
||||
bones/19/scale = Vector3(1, 1, 1)
|
||||
bones/20/position = Vector3(-2.2286711e-10, 0.007071072, 0)
|
||||
bones/20/rotation = Quaternion(-0.112210214, -0.47133064, -0.13382514, 0.8644924)
|
||||
bones/20/rotation = Quaternion(-0.11203431, -0.4710411, -0.13362855, 0.8647035)
|
||||
bones/20/scale = Vector3(1, 0.9999999, 1)
|
||||
bones/22/position = Vector3(0.011061782, -0.0085772155, 0.0025831666)
|
||||
bones/22/position = Vector3(0.01127276, -0.0085772155, 0.0025254297)
|
||||
bones/22/rotation = Quaternion(3.090862e-08, 0.70710677, 0.70710677, 3.090862e-08)
|
||||
bones/22/scale = Vector3(1, 1, 1)
|
||||
bones/24/position = Vector3(-0.011000002, 0.0050000013, 0.0070000007)
|
||||
@ -151,8 +152,11 @@ relative = true
|
||||
origin_from = 2
|
||||
origin_external_node = NodePath("../../../../look_at_root")
|
||||
|
||||
[node name="player_hand_remover" type="PlayerHandRemover" parent="SoldierM/Soldier/Skeleton3D" index="4" unique_id=2077460571]
|
||||
transform = Transform3D(1, -2.2737368e-13, 0, 2.2737368e-13, 1, 0, -1.3552527e-20, 0, 1, 0, 0, 0)
|
||||
|
||||
[node name="bone_attachment_3d" type="BoneAttachment3D" parent="." unique_id=1964353847]
|
||||
transform = Transform3D(-35.07064, 3.824201, -93.57043, -83.59483, 43.760143, 33.120216, 42.213154, 89.83552, -12.150139, -0.47213513, 3.3899364, 0.7408379)
|
||||
transform = Transform3D(-35.09831, 3.8198574, -93.56024, -83.58222, 43.767776, 33.14208, 42.21521, 89.832, -12.169015, -0.47216344, 3.3898914, 0.7404115)
|
||||
bone_name = "HAND.R_end"
|
||||
bone_idx = 17
|
||||
use_external_skeleton = true
|
||||
|
||||
@ -7,6 +7,7 @@ pub mod map;
|
||||
pub mod map_resource;
|
||||
pub mod net;
|
||||
pub mod player;
|
||||
pub mod player_hand_remover;
|
||||
pub mod soldier_mesh;
|
||||
pub mod ui;
|
||||
pub mod weapon;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use teanet::{Peer, PeerMessage};
|
||||
use teanet::PeerMessage;
|
||||
|
||||
use crate::{
|
||||
game_manager::{Game, GameManager},
|
||||
|
||||
@ -20,9 +20,10 @@ use crate::{
|
||||
},
|
||||
util::{NetVector3, cast_ray},
|
||||
},
|
||||
player_hand_remover::PlayerHandRemover,
|
||||
soldier_mesh::SoldierMesh,
|
||||
ui::cli::CommandLinePanel,
|
||||
weapon::{BallWeapon, Weapon, WeaponType},
|
||||
weapon::{BallWeapon, Raygun, Weapon, WeaponType},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
@ -154,10 +155,14 @@ pub struct LocalPlayer {
|
||||
#[export]
|
||||
ball_origin: Option<Gd<Node3D>>,
|
||||
#[export]
|
||||
weapon_node: Option<Gd<Node3D>>,
|
||||
#[export]
|
||||
health: i32,
|
||||
|
||||
pub player_id: Option<u16>,
|
||||
|
||||
pub weapon: Option<DynGd<Node3D, dyn Weapon>>,
|
||||
|
||||
movement_dir: Vector3,
|
||||
y_speed: f32,
|
||||
look_up: f32,
|
||||
@ -292,18 +297,24 @@ impl IPlayer for LocalPlayer {
|
||||
}
|
||||
|
||||
fn swap_weapon(&mut self, weapon: WeaponType) {
|
||||
if let Some(mesh) = &mut self.soldier_mesh {
|
||||
if let Some(mesh) = self.soldier_mesh.clone() {
|
||||
match weapon {
|
||||
WeaponType::Raygun => mesh.bind_mut().spawn_raygun(),
|
||||
WeaponType::Ball => mesh.bind_mut().spawn_ball(),
|
||||
WeaponType::Raygun => {
|
||||
if let Some(raygun) = &mesh.bind().raygun {
|
||||
self.spawn_weapon(raygun.instantiate_as::<Raygun>().into_dyn().upcast());
|
||||
}
|
||||
}
|
||||
WeaponType::Ball => {
|
||||
if let Some(ball) = &mesh.bind().ball {
|
||||
self.spawn_weapon(ball.instantiate_as::<BallWeapon>().into_dyn().upcast());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn get_weapon(&self) -> Option<DynGd<Node3D, dyn Weapon>> {
|
||||
self.soldier_mesh
|
||||
.as_ref()
|
||||
.and_then(|m| m.bind().get_weapon())
|
||||
self.weapon.clone()
|
||||
}
|
||||
|
||||
fn drop_ball(&mut self, with_velocity: bool) -> bool {
|
||||
@ -338,6 +349,12 @@ impl ICharacterBody3D for LocalPlayer {
|
||||
if let Some(camera) = &mut self.camera {
|
||||
camera.set_current(true);
|
||||
}
|
||||
|
||||
if let Some(mesh) = &mut self.soldier_mesh
|
||||
&& let Some(remover) = &mut mesh.bind_mut().hand_remover
|
||||
{
|
||||
remover.bind_mut().active = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn process(&mut self, delta: f64) {
|
||||
@ -489,6 +506,16 @@ impl LocalPlayer {
|
||||
Input::singleton().set_mouse_mode(MouseMode::VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_weapon(&mut self, weapon: DynGd<Node3D, dyn Weapon>) {
|
||||
if let Some(mut weapon) = self.weapon.take() {
|
||||
weapon.queue_free();
|
||||
}
|
||||
if let Some(weapon_node) = &mut self.weapon_node {
|
||||
weapon_node.add_child(&weapon);
|
||||
self.weapon = Some(weapon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(GodotClass)]
|
||||
|
||||
26
rust/src/player_hand_remover.rs
Normal file
26
rust/src/player_hand_remover.rs
Normal file
@ -0,0 +1,26 @@
|
||||
use godot::{
|
||||
classes::{ISkeletonModifier3D, SkeletonModifier3D},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
#[derive(GodotClass)]
|
||||
#[class(base=SkeletonModifier3D, init)]
|
||||
pub struct PlayerHandRemover {
|
||||
pub active: bool,
|
||||
|
||||
base: Base<SkeletonModifier3D>,
|
||||
}
|
||||
|
||||
#[godot_api]
|
||||
impl ISkeletonModifier3D for PlayerHandRemover {
|
||||
fn process_modification_with_delta(&mut self, delta: f64) {
|
||||
if self.active {
|
||||
if let Some(mut skeleton) = self.base_mut().get_skeleton() {
|
||||
let uar = skeleton.find_bone("UA.R");
|
||||
let ual = skeleton.find_bone("UA.L");
|
||||
skeleton.set_bone_pose_scale(uar, Vector3::ZERO);
|
||||
skeleton.set_bone_pose_scale(ual, Vector3::ZERO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,10 @@ use godot::{
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
use crate::weapon::{BallWeapon, Raygun, Weapon};
|
||||
use crate::{
|
||||
player_hand_remover::PlayerHandRemover,
|
||||
weapon::{BallWeapon, Raygun, Weapon},
|
||||
};
|
||||
|
||||
#[derive(GodotClass)]
|
||||
#[class(base=Node3D, init)]
|
||||
@ -15,11 +18,13 @@ pub struct SoldierMesh {
|
||||
#[export]
|
||||
skeleton: Option<Gd<Skeleton3D>>,
|
||||
#[export]
|
||||
raygun: Option<Gd<PackedScene>>,
|
||||
pub raygun: Option<Gd<PackedScene>>,
|
||||
#[export]
|
||||
ball: Option<Gd<PackedScene>>,
|
||||
pub ball: Option<Gd<PackedScene>>,
|
||||
#[export]
|
||||
look_at: Option<Gd<Node3D>>,
|
||||
#[export]
|
||||
pub hand_remover: Option<Gd<PlayerHandRemover>>,
|
||||
|
||||
pub current_weapon: Option<DynGd<Node3D, dyn Weapon>>,
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user