From d79411b7e73d3fa2635bd7dcdc94b0de7e890f58 Mon Sep 17 00:00:00 2001 From: Sofia Date: Sun, 26 Jul 2026 20:50:13 +0300 Subject: [PATCH] Use separate ball for replays --- godot/maps/default_map/map0.tscn | 2 ++ godot/scenes/misc/replay_ball.tscn | 16 ++++++++++++++++ rust/src/map.rs | 29 +++++++++++++++++++++++++++++ rust/src/replay.rs | 2 +- 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 godot/scenes/misc/replay_ball.tscn diff --git a/godot/maps/default_map/map0.tscn b/godot/maps/default_map/map0.tscn index 1fc2762..2ae7f2b 100644 --- a/godot/maps/default_map/map0.tscn +++ b/godot/maps/default_map/map0.tscn @@ -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://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://dc17w5n6y1an" path="res://scenes/misc/replay_ball.tscn" id="5_oqkce"] [sub_resource type="ImageTexture" id="ImageTexture_3vyb7"] @@ -27,6 +28,7 @@ local_player = ExtResource("1_yjvui") remote_player = ExtResource("2_kcncr") replay_player = ExtResource("3_8af6u") ball = ExtResource("3_e0nj3") +replay_ball = ExtResource("5_oqkce") [node name="terrain" type="MeshInstance3D" parent="." unique_id=1474127252] material_override = SubResource("StandardMaterial3D_u8vuu") diff --git a/godot/scenes/misc/replay_ball.tscn b/godot/scenes/misc/replay_ball.tscn new file mode 100644 index 0000000..4e1e498 --- /dev/null +++ b/godot/scenes/misc/replay_ball.tscn @@ -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") diff --git a/rust/src/map.rs b/rust/src/map.rs index 6d1b6e2..cd23534 100644 --- a/rust/src/map.rs +++ b/rust/src/map.rs @@ -24,6 +24,8 @@ pub struct Map { pub replay_player: Option>, #[export] pub ball: Option>, + #[export] + pub replay_ball: Option>, base: Base, } @@ -147,4 +149,31 @@ impl Map { None } } + + pub fn spawn_replay_ball( + &mut self, + transform: Option, + velocity: Option, + player_id: Option, + ) -> Option> { + if let Some(ball_spawner) = self.ball_spawner.clone() + && let Some(ball_prefab) = &self.replay_ball + { + let mut ball = ball_prefab.instantiate_as::(); + 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 + } + } } diff --git a/rust/src/replay.rs b/rust/src/replay.rs index 6a4fe32..3c5cf44 100644 --- a/rust/src/replay.rs +++ b/rust/src/replay.rs @@ -57,7 +57,7 @@ impl INode for ReplayPlayback { velocity: ball_state.velocity, }); } 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.velocity.into(), None,