Use separate ball for replays

This commit is contained in:
Sofia 2026-07-26 20:50:13 +03:00
parent 8abcd9ec68
commit d79411b7e7
4 changed files with 48 additions and 1 deletions

View File

@ -5,6 +5,7 @@
[ext_resource type="PackedScene" uid="uid://hmh2lrrlo2wy" path="res://scenes/player/replay_player.tscn" id="3_8af6u"] [ext_resource type="PackedScene" uid="uid://hmh2lrrlo2wy" path="res://scenes/player/replay_player.tscn" id="3_8af6u"]
[ext_resource type="PackedScene" uid="uid://dfnbc8sbufa4j" path="res://scenes/misc/ball.tscn" id="3_e0nj3"] [ext_resource type="PackedScene" uid="uid://dfnbc8sbufa4j" path="res://scenes/misc/ball.tscn" id="3_e0nj3"]
[ext_resource type="PackedScene" uid="uid://c1r8nk58cci3a" path="res://scenes/misc/goal.tscn" id="4_w7til"] [ext_resource type="PackedScene" uid="uid://c1r8nk58cci3a" path="res://scenes/misc/goal.tscn" id="4_w7til"]
[ext_resource type="PackedScene" uid="uid://dc17w5n6y1an" path="res://scenes/misc/replay_ball.tscn" id="5_oqkce"]
[sub_resource type="ImageTexture" id="ImageTexture_3vyb7"] [sub_resource type="ImageTexture" id="ImageTexture_3vyb7"]
@ -27,6 +28,7 @@ local_player = ExtResource("1_yjvui")
remote_player = ExtResource("2_kcncr") remote_player = ExtResource("2_kcncr")
replay_player = ExtResource("3_8af6u") replay_player = ExtResource("3_8af6u")
ball = ExtResource("3_e0nj3") ball = ExtResource("3_e0nj3")
replay_ball = ExtResource("5_oqkce")
[node name="terrain" type="MeshInstance3D" parent="." unique_id=1474127252] [node name="terrain" type="MeshInstance3D" parent="." unique_id=1474127252]
material_override = SubResource("StandardMaterial3D_u8vuu") material_override = SubResource("StandardMaterial3D_u8vuu")

View File

@ -0,0 +1,16 @@
[gd_scene format=3 uid="uid://dc17w5n6y1an"]
[ext_resource type="PackedScene" uid="uid://r13poamopmnv" path="res://mesh/ball_mesh.tscn" id="1_ishne"]
[sub_resource type="SphereShape3D" id="SphereShape3D_1cgct"]
[node name="replay_ball" type="Ball" unique_id=816748600]
collision_layer = 8
collision_mask = 4
contact_monitor = true
max_contacts_reported = 10
[node name="mesh_instance_3d" parent="." unique_id=37904686 instance=ExtResource("1_ishne")]
[node name="collision_shape_3d" type="CollisionShape3D" parent="." unique_id=1408432914]
shape = SubResource("SphereShape3D_1cgct")

View File

@ -24,6 +24,8 @@ pub struct Map {
pub replay_player: Option<Gd<PackedScene>>, pub replay_player: Option<Gd<PackedScene>>,
#[export] #[export]
pub ball: Option<Gd<PackedScene>>, pub ball: Option<Gd<PackedScene>>,
#[export]
pub replay_ball: Option<Gd<PackedScene>>,
base: Base<Node3D>, base: Base<Node3D>,
} }
@ -147,4 +149,31 @@ impl Map {
None None
} }
} }
pub fn spawn_replay_ball(
&mut self,
transform: Option<NetTransform>,
velocity: Option<NetVector3>,
player_id: Option<u16>,
) -> Option<Gd<Ball>> {
if let Some(ball_spawner) = self.ball_spawner.clone()
&& let Some(ball_prefab) = &self.replay_ball
{
let mut ball = ball_prefab.instantiate_as::<Ball>();
ball.bind_mut().dropper = player_id;
self.base_mut().add_child(&ball);
if let Some(transform) = transform {
ball.set_global_position(transform.location.into());
ball.set_global_rotation(transform.rotation.into());
} else {
ball.set_global_position(ball_spawner.get_global_position());
}
if let Some(velocity) = velocity {
ball.set_linear_velocity(velocity.into());
}
Some(ball)
} else {
None
}
}
} }

View File

@ -57,7 +57,7 @@ impl INode for ReplayPlayback {
velocity: ball_state.velocity, velocity: ball_state.velocity,
}); });
} else if let Some(map) = &mut self.current_map { } else if let Some(map) = &mut self.current_map {
if let Some(ball) = map.bind_mut().spawn_ball( if let Some(ball) = map.bind_mut().spawn_replay_ball(
ball_state.transform.into(), ball_state.transform.into(),
ball_state.velocity.into(), ball_state.velocity.into(),
None, None,