Add name labels
This commit is contained in:
parent
c937635efe
commit
949585dc5c
@ -5,7 +5,7 @@
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_1cgct"]
|
||||
|
||||
[node name="player" type="RemotePlayer" unique_id=845968872 node_paths=PackedStringArray("soldier_mesh", "collider", "splorch", "spectator_camera", "ball_origin")]
|
||||
[node name="player" type="RemotePlayer" unique_id=845968872 node_paths=PackedStringArray("soldier_mesh", "collider", "splorch", "spectator_camera", "ball_origin", "name_label")]
|
||||
move_speed = 5.0
|
||||
soldier_mesh = NodePath("soldier_m")
|
||||
collider = NodePath("collision_shape_3d")
|
||||
@ -13,6 +13,7 @@ splorch = NodePath("gpu_particles_3d")
|
||||
health = 100
|
||||
spectator_camera = NodePath("spectate_root/spectate_camera")
|
||||
ball_origin = NodePath("ball_origin")
|
||||
name_label = NodePath("name_label")
|
||||
collision_layer = 2
|
||||
collision_mask = 4
|
||||
|
||||
@ -34,3 +35,7 @@ transform = Transform3D(1, 0, 0, 0, 0.89379096, 0.44848388, 0, -0.44848388, 0.89
|
||||
|
||||
[node name="ball_origin" type="Node3D" parent="." unique_id=1445680156]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.8724979, -0.2644562)
|
||||
|
||||
[node name="name_label" type="Label3D" parent="." unique_id=142179925]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.3304863, 0)
|
||||
billboard = 1
|
||||
|
||||
@ -3,7 +3,7 @@ use std::{f32::consts::PI, ops::Neg};
|
||||
use godot::{
|
||||
classes::{
|
||||
Camera3D, CharacterBody3D, CollisionShape3D, GpuParticles3D, ICharacterBody3D, Input,
|
||||
InputEvent, InputEventMouseMotion, Label, input::MouseMode,
|
||||
InputEvent, InputEventMouseMotion, Label, Label3D, input::MouseMode,
|
||||
},
|
||||
obj::WithBaseField,
|
||||
prelude::*,
|
||||
@ -535,6 +535,8 @@ pub struct RemotePlayer {
|
||||
spectator_camera: Option<Gd<Camera3D>>,
|
||||
#[export]
|
||||
ball_origin: Option<Gd<Node3D>>,
|
||||
#[export]
|
||||
name_label: Option<Gd<Label3D>>,
|
||||
|
||||
pub player_id: Option<u16>,
|
||||
|
||||
@ -692,6 +694,18 @@ impl IPlayer for RemotePlayer {
|
||||
#[godot_api]
|
||||
impl ICharacterBody3D for RemotePlayer {
|
||||
fn ready(&mut self) {
|
||||
self.run_deferred(|s| {
|
||||
if let Some(player_id) = s.player_id
|
||||
&& let Some(game) = Game::singleton()
|
||||
&& let Some(player) = game.bind().find_player(player_id)
|
||||
&& let Some(team) = game.bind().get_team(player.data.team)
|
||||
&& let Some(name_label) = &mut s.name_label
|
||||
{
|
||||
name_label.set_text(&player.data.name);
|
||||
name_label.set_modulate(team.bind().color);
|
||||
}
|
||||
});
|
||||
|
||||
self.swap_weapon(WeaponType::Raygun);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user