From e810836675cacf8484b3c275deb4b33e8403e424 Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Tue, 11 Feb 2025 20:29:33 +0300 Subject: [PATCH] pick up bombs or something --- project.godot | 5 +++++ src/ingame/ingame.tscn | 3 +++ src/ingame/player.gd | 27 +++++++++++++++++++++++++-- src/ingame/player.tscn | 22 ++++++++++++++++++++-- src/ingame/sprout.tscn | 1 + src/ingame/water_bomb.gd | 8 ++++++++ src/ingame/water_bomb.tscn | 23 ++++++++++++----------- 7 files changed, 74 insertions(+), 15 deletions(-) diff --git a/project.godot b/project.godot index b196c6b..9a28d19 100644 --- a/project.godot +++ b/project.godot @@ -67,6 +67,11 @@ fire={ "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null) ] } +pick={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":70,"key_label":0,"unicode":102,"location":0,"echo":false,"script":null) +] +} [layer_names] diff --git a/src/ingame/ingame.tscn b/src/ingame/ingame.tscn index b67fd90..304239f 100644 --- a/src/ingame/ingame.tscn +++ b/src/ingame/ingame.tscn @@ -222,6 +222,9 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.60402, 0.396167, 2.77978) [node name="Sprout6" parent="Plants" instance=ExtResource("3_2xvqq")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.59598, 0.396167, 2.77978) +[node name="Sprout19" parent="Plants" instance=ExtResource("3_2xvqq")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -7.27774, 0.866392, 8.06555) + [node name="Sprout7" parent="Plants" instance=ExtResource("3_2xvqq")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00401986, 0.396167, 3.37978) diff --git a/src/ingame/player.gd b/src/ingame/player.gd index a3b5b62..1821ed0 100644 --- a/src/ingame/player.gd +++ b/src/ingame/player.gd @@ -10,6 +10,7 @@ const JUMP_VELOCITY = 4.5 @export var _projectile_point: Marker3D @export var _camera_pivot: Node3D @export var _camera: Camera3D +@export var _line_of_sight: ShapeCast3D @export var _shot_sound: AudioStreamPlayer3D @export var id: int @@ -22,7 +23,7 @@ var _mouse_sensitivity := 0.008 # radians/pixel var _projectile_speed := 12.0 var controls_disabled := false - +var held_thing: String # What the others see. func _init_bystander() -> void: @@ -72,6 +73,18 @@ func _physics_process(delta: float) -> void: move_and_slide() +@rpc("any_peer", "call_local", "reliable") +func hold_thing() -> void: + held_thing = "water" + _camera_pivot.get_node("HeldViewmodel").show() + + +@rpc("any_peer", "call_local", "reliable") +func throw_thing() -> void: + held_thing = "" + _camera_pivot.get_node("HeldViewmodel").hide() + + func _unhandled_input(event: InputEvent) -> void: if controls_disabled or id != multiplayer.get_unique_id(): return @@ -82,7 +95,16 @@ func _unhandled_input(event: InputEvent) -> void: _camera_pivot.rotation.x = clamp(_camera_pivot.rotation.x, -1.2, 1.2) return - if event.is_action_pressed("fire"): + if event.is_action_pressed("pick") and held_thing == "": + if _line_of_sight.is_colliding(): + if id != 1: + print("test") + # TODO: bad + var picked = _line_of_sight.get_collider(0).get_parent() + picked.get_picked_up.rpc() + hold_thing.rpc() + + if event.is_action_pressed("fire") and held_thing != "": var new_projectile: Node3D = _projectile_scene.instantiate() _projectile_holder.add_child(new_projectile, true) _set_projectile_authority.rpc(new_projectile.get_path(), id) @@ -93,6 +115,7 @@ func _unhandled_input(event: InputEvent) -> void: new_projectile.body.linear_velocity = -_camera.global_basis.z * _projectile_speed _shot_sound.play() + throw_thing.rpc() @rpc("authority", "call_local", "reliable") diff --git a/src/ingame/player.tscn b/src/ingame/player.tscn index fe4c568..ed89fd8 100644 --- a/src/ingame/player.tscn +++ b/src/ingame/player.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=7 format=3 uid="uid://cs8c570bxh6u"] +[gd_scene load_steps=9 format=3 uid="uid://cs8c570bxh6u"] [ext_resource type="Script" path="res://src/ingame/player.gd" id="1_isrmf"] [ext_resource type="PackedScene" uid="uid://tdsbo3e5ic86" path="res://src/ingame/water_bomb.tscn" id="2_naek4"] [ext_resource type="AudioStream" uid="uid://3dlhs18w1fa2" path="res://assets/sfx/boom.wav" id="3_u2hxa"] +[ext_resource type="PackedScene" uid="uid://s2a1pry5fw8f" path="res://scenes/water_bomb_model.tscn" id="4_bfvih"] [sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_2xotl"] properties/0/path = NodePath(".:position") @@ -28,7 +29,9 @@ properties/5/replication_mode = 2 [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_f4jjl"] -[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("_projectile_holder", "_projectile_point", "_camera_pivot", "_camera", "_shot_sound")] +[sub_resource type="SphereShape3D" id="SphereShape3D_rsfjy"] + +[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("_projectile_holder", "_projectile_point", "_camera_pivot", "_camera", "_line_of_sight", "_shot_sound")] collision_layer = 2 script = ExtResource("1_isrmf") _projectile_scene = ExtResource("2_naek4") @@ -36,6 +39,7 @@ _projectile_holder = NodePath("ProjectileHolder") _projectile_point = NodePath("ProjectilePoint") _camera_pivot = NodePath("CameraPivot") _camera = NodePath("CameraPivot/Camera3D") +_line_of_sight = NodePath("CameraPivot/LineOfSight") _shot_sound = NodePath("ShotSound") [node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."] @@ -66,6 +70,20 @@ shape = SubResource("CapsuleShape3D_f4jjl") [node name="Camera3D" type="Camera3D" parent="CameraPivot"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.6, 0) +[node name="LineOfSight" type="ShapeCast3D" parent="CameraPivot"] +shape = SubResource("SphereShape3D_rsfjy") +target_position = Vector3(0, 0, -2) +collision_mask = 16 +collide_with_areas = true +collide_with_bodies = false +debug_shape_custom_color = Color(0.628721, 0, 0.256939, 1) + +[node name="HeldViewmodel" type="Node3D" parent="CameraPivot"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.2, -1) +visible = false + +[node name="Model" parent="CameraPivot/HeldViewmodel" instance=ExtResource("4_bfvih")] + [node name="ShotSound" type="AudioStreamPlayer3D" parent="."] stream = ExtResource("3_u2hxa") bus = &"SoundEffects" diff --git a/src/ingame/sprout.tscn b/src/ingame/sprout.tscn index 63a81da..4e0cee5 100644 --- a/src/ingame/sprout.tscn +++ b/src/ingame/sprout.tscn @@ -43,6 +43,7 @@ texture = ExtResource("3_kghdv") [node name="Area3D" type="Area3D" parent="."] collision_layer = 8 collision_mask = 0 +monitoring = false [node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"] shape = SubResource("CapsuleShape3D_cwbye") diff --git a/src/ingame/water_bomb.gd b/src/ingame/water_bomb.gd index 75d30a6..ebdd8c6 100644 --- a/src/ingame/water_bomb.gd +++ b/src/ingame/water_bomb.gd @@ -4,6 +4,7 @@ extends Node3D @export var _splash_small_quiet_sound: AudioStreamPlayer3D @export var _model: Node3D @export var _splash_particles: GPUParticles3D +@export var _picking_area: Area3D @export var body: RigidBody3D ## no longer exists and shouldn't be considered, but not ready to be freed yet @export var is_dead := false @@ -48,6 +49,7 @@ func _on_body_entered(p_body: Node3D) -> void: is_dead = true _model.hide() + _picking_area.collision_layer = 0 _disable_body.rpc() await _splash_small_sound.finished @@ -69,3 +71,9 @@ func set_global_pos(new: Vector3) -> void: global_position = new body.global_position = new body.reset_physics_interpolation() + + +@rpc("any_peer", "call_local", "reliable") +func get_picked_up() -> void: + if is_multiplayer_authority(): + queue_free() diff --git a/src/ingame/water_bomb.tscn b/src/ingame/water_bomb.tscn index 53bb5c0..630ee0a 100644 --- a/src/ingame/water_bomb.tscn +++ b/src/ingame/water_bomb.tscn @@ -1,6 +1,7 @@ [gd_scene load_steps=11 format=3 uid="uid://tdsbo3e5ic86"] [ext_resource type="Script" path="res://src/ingame/water_bomb.gd" id="1_lk5fq"] +[ext_resource type="PackedScene" uid="uid://s2a1pry5fw8f" path="res://scenes/water_bomb_model.tscn" id="2_0lxuq"] [ext_resource type="AudioStream" uid="uid://dtjpv2b74g24m" path="res://assets/sfx/splash-small.wav" id="2_0wk8g"] [ext_resource type="AudioStream" uid="uid://blgrl2wl05feq" path="res://assets/sfx/splash-small-quiet.wav" id="3_hgy7l"] @@ -24,11 +25,6 @@ properties/5/path = NodePath("SplashParticles:emitting") properties/5/spawn = true properties/5/replication_mode = 2 -[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ptaep"] -albedo_color = Color(0.0936238, 0.825356, 1, 1) -metallic = 0.8 -roughness = 0.4 - [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_v7dnr"] albedo_color = Color(0, 1, 1, 1) roughness = 0.2 @@ -50,22 +46,19 @@ radius = 0.2 [sub_resource type="SphereShape3D" id="SphereShape3D_y6453"] radius = 1.5 -[node name="WaterBomb" type="Node3D" node_paths=PackedStringArray("_splash_small_sound", "_splash_small_quiet_sound", "_model", "_splash_particles", "body")] +[node name="WaterBomb" type="Node3D" node_paths=PackedStringArray("_splash_small_sound", "_splash_small_quiet_sound", "_model", "_splash_particles", "_picking_area", "body")] script = ExtResource("1_lk5fq") _splash_small_sound = NodePath("SplashSmallSound") _splash_small_quiet_sound = NodePath("SplashSmallQuietSound") _model = NodePath("Model") _splash_particles = NodePath("SplashParticles") +_picking_area = NodePath("PickingArea") body = NodePath("RigidBody3D") [node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."] replication_config = SubResource("SceneReplicationConfig_0ebrr") -[node name="Model" type="CSGSphere3D" parent="."] -material_override = SubResource("StandardMaterial3D_ptaep") -radius = 0.2 -radial_segments = 24 -rings = 12 +[node name="Model" parent="." instance=ExtResource("2_0lxuq")] [node name="SplashParticles" type="GPUParticles3D" parent="."] material_override = SubResource("StandardMaterial3D_v7dnr") @@ -106,6 +99,14 @@ bus = &"SoundEffects" stream = ExtResource("3_hgy7l") bus = &"SoundEffects" +[node name="PickingArea" type="Area3D" parent="."] +collision_layer = 16 +collision_mask = 0 +monitoring = false + +[node name="CollisionShape3D" type="CollisionShape3D" parent="PickingArea"] +shape = SubResource("SphereShape3D_6c830") + [connection signal="body_entered" from="RigidBody3D" to="." method="_on_body_entered"] [connection signal="area_entered" from="RigidBody3D/SplashArea" to="." method="_on_splash_area_entered"] [connection signal="area_exited" from="RigidBody3D/SplashArea" to="." method="_on_splash_area_exited"]