diff --git a/objects/canny_cat.gd b/objects/canny_cat.gd index 1fb1f84..591f790 100644 --- a/objects/canny_cat.gd +++ b/objects/canny_cat.gd @@ -43,9 +43,10 @@ var power: float = 0.0: var charging_power: bool = false var prev_velocity: Vector3 = Vector3.ZERO -var _entered_goal: Node3D = self +var _entered_goal: Node3D = null +#region Builtin Overrides func _ready() -> void: Input.mouse_mode = Input.MOUSE_MODE_CAPTURED @@ -70,12 +71,18 @@ func _unhandled_input(event: InputEvent) -> void: else: camera_arm.rotation.x -= event.screen_relative.y * camera_pitch_sensitivity camera_arm.rotation.x = clampf(camera_arm.rotation.x, -camera_high_angle, -camera_low_angle) +#endregion #region Public Functions func enter_goal(goal: GoalPost) -> void: _entered_goal = goal state_chart.send_event(&"goal_entered") + + +func attach_to_pole(pole: WatermanPole) -> void: + _attached_pole = pole + state_chart.send_event(&"pole_attached") #endregion @@ -151,3 +158,44 @@ func _start_winning() -> void: tween.set_parallel(true) tween.tween_property(graphics, ^"global_position", _entered_goal.global_position, goal_animation_time) #endregion + + +#region Pole Spinning +var _attached_pole: WatermanPole = null +var _pole_angle: float = 0.0 + +func _start_pole_spin() -> void: + velocity = Vector3.ZERO + var pole_xz = flatten_vector(_attached_pole.global_position) + var self_xz = flatten_vector(global_position) + _pole_angle = Vector3.FORWARD.angle_to(self_xz - pole_xz) + +func _process_pole_spin(delta: float) -> void: + # rise + global_position.y += _attached_pole.rise_speed * delta + global_position.y = clampf( + global_position.y, + _attached_pole.global_position.y, + _attached_pole.top.global_position.y + ) + + # spin + _pole_angle += _attached_pole.spin_speed * delta + var pole_xz = flatten_vector(_attached_pole.global_position) + var self_dir = Vector3.FORWARD.rotated(Vector3.UP, _pole_angle) + var self_xz = pole_xz + self_dir * _attached_pole.offset + global_position.x = self_xz.x + global_position.z = self_xz.z + +func _end_pole_spin() -> void: + var pole_xz = flatten_vector(_attached_pole.global_position) + var impulse = Vector3.FORWARD.rotated(Vector3.UP, _pole_angle) * _attached_pole.release_boost + velocity.x = impulse.x + velocity.z = impulse.z +#endregion + + +#region Helpers +func flatten_vector(vector: Vector3) -> Vector3: + return Vector3(vector.x, 0.0, vector.z) +#endregion diff --git a/objects/canny_cat.tscn b/objects/canny_cat.tscn index 3e087ef..08e22ba 100644 --- a/objects/canny_cat.tscn +++ b/objects/canny_cat.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=19 format=3 uid="uid://cybm74xwbsivx"] +[gd_scene load_steps=20 format=3 uid="uid://cybm74xwbsivx"] [ext_resource type="Texture2D" uid="uid://3i17aqnrspma" path="res://assets/textures/player/canny.png" id="1_cp4br"] [ext_resource type="Script" path="res://objects/canny_cat.gd" id="1_twfq8"] @@ -26,6 +26,16 @@ albedo_color = Color(0.916968, 0.113727, 0, 1) [sub_resource type="SphereShape3D" id="SphereShape3D_4o01j"] radius = 0.9 +[sub_resource type="AudioStreamInteractive" id="AudioStreamInteractive_plnjn"] +clip_count = 3 +clip_0/name = &"" +clip_0/auto_advance = 0 +clip_1/name = &"" +clip_1/auto_advance = 1 +clip_1/next_clip = 0 +clip_2/name = &"" +clip_2/auto_advance = 0 + [sub_resource type="CylinderMesh" id="CylinderMesh_b16dl"] top_radius = 0.05 bottom_radius = 0.05 @@ -101,6 +111,10 @@ bus = &"Sounds" stream = ExtResource("5_v6u4q") bus = &"Sounds" +[node name="ChargeCancel2" type="AudioStreamPlayer3D" parent="Sounds"] +stream = SubResource("AudioStreamInteractive_plnjn") +bus = &"Sounds" + [node name="Shoot" type="AudioStreamPlayer3D" parent="Sounds"] stream = ExtResource("6_a7neg") bus = &"Sounds" @@ -143,6 +157,12 @@ to = NodePath("../Winning") event = &"goal_entered" delay_in_seconds = "0.0" +[node name="on PoleAttached" type="Node" parent="StateChart/Root"] +script = ExtResource("7_epv8h") +to = NodePath("../PoleSpinning") +event = &"pole_attached" +delay_in_seconds = "0.0" + [node name="Idle" type="Node" parent="StateChart/Root"] script = ExtResource("6_bu01i") @@ -179,15 +199,27 @@ delay_in_seconds = "0.0" [node name="Winning" type="Node" parent="StateChart/Root"] script = ExtResource("6_bu01i") +[node name="PoleSpinning" type="Node" parent="StateChart/Root"] +script = ExtResource("6_bu01i") + +[node name="Transition" type="Node" parent="StateChart/Root/PoleSpinning"] +script = ExtResource("7_epv8h") +to = NodePath("../../Moving") +event = &"charge_pressed" +delay_in_seconds = "0.0" + [connection signal="bounced" from="." to="Sounds/WallBounce" method="play"] [connection signal="charge_canceled" from="." to="Sounds/ChargeCancel" method="play"] [connection signal="shot" from="." to="Sounds/Shoot" method="play"] [connection signal="state_physics_processing" from="StateChart/Root/Idle" to="." method="_apply_gravity"] [connection signal="state_physics_processing" from="StateChart/Root/Moving" to="." method="_bounce_on_walls"] -[connection signal="state_physics_processing" from="StateChart/Root/Moving" to="." method="_slow_to_stop"] [connection signal="state_physics_processing" from="StateChart/Root/Moving" to="." method="_apply_gravity"] +[connection signal="state_physics_processing" from="StateChart/Root/Moving" to="." method="_slow_to_stop"] [connection signal="state_entered" from="StateChart/Root/Charging" to="." method="_start_charge"] [connection signal="state_entered" from="StateChart/Root/Charging" to="Sounds/ChargeStart" method="play"] [connection signal="state_exited" from="StateChart/Root/Charging" to="." method="_end_charge"] [connection signal="state_physics_processing" from="StateChart/Root/Charging" to="." method="_update_charge"] [connection signal="state_entered" from="StateChart/Root/Winning" to="." method="_start_winning"] +[connection signal="state_entered" from="StateChart/Root/PoleSpinning" to="." method="_start_pole_spin"] +[connection signal="state_exited" from="StateChart/Root/PoleSpinning" to="." method="_end_pole_spin"] +[connection signal="state_physics_processing" from="StateChart/Root/PoleSpinning" to="." method="_process_pole_spin"] diff --git a/objects/waterman_pole.gd b/objects/waterman_pole.gd new file mode 100644 index 0000000..58974b2 --- /dev/null +++ b/objects/waterman_pole.gd @@ -0,0 +1,17 @@ +class_name WatermanPole +extends Node3D + + +@export var rise_speed: float +@export_range(-1,1,0.5,"or_less","or_greater","radians_as_degrees") +var spin_speed: float +@export var offset: float +@export var release_boost: float + +@export_group("Node References") +@export var top: Node3D + + +func _on_player_detector_body_entered(body: Node3D) -> void: + if body is Player: + body.attach_to_pole(self) diff --git a/objects/waterman_pole.tscn b/objects/waterman_pole.tscn new file mode 100644 index 0000000..7a5b0aa --- /dev/null +++ b/objects/waterman_pole.tscn @@ -0,0 +1,54 @@ +[gd_scene load_steps=6 format=3 uid="uid://13qlrib2dk36"] + +[ext_resource type="Script" path="res://objects/waterman_pole.gd" id="1_8whes"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_6xwjl"] +shading_mode = 2 +specular_mode = 2 +albedo_color = Color(3.27289e-06, 0.685269, 0.929658, 1) +metallic_specular = 0.0 + +[sub_resource type="CylinderMesh" id="CylinderMesh_nbwjg"] +top_radius = 0.25 +bottom_radius = 0.25 +height = 1.0 +radial_segments = 6 +rings = 8 + +[sub_resource type="CylinderShape3D" id="CylinderShape3D_28fhu"] +height = 1.0 +radius = 0.25 + +[sub_resource type="CylinderShape3D" id="CylinderShape3D_o6xmv"] +height = 1.0 +radius = 0.4 + +[node name="WatermanPole" type="Node3D" node_paths=PackedStringArray("top")] +script = ExtResource("1_8whes") +top = NodePath("Top") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0) +material_override = SubResource("StandardMaterial3D_6xwjl") +mesh = SubResource("CylinderMesh_nbwjg") + +[node name="StaticBody3D" type="StaticBody3D" parent="."] +collision_mask = 0 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0) +shape = SubResource("CylinderShape3D_28fhu") + +[node name="PlayerDetector" type="Area3D" parent="."] +collision_layer = 0 +collision_mask = 16 +monitorable = false + +[node name="CollisionShape3D" type="CollisionShape3D" parent="PlayerDetector"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0) +shape = SubResource("CylinderShape3D_o6xmv") + +[node name="Top" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) + +[connection signal="body_entered" from="PlayerDetector" to="." method="_on_player_detector_body_entered"] diff --git a/test_scene.tscn b/test_scene.tscn index b45f96e..5ee19a4 100644 --- a/test_scene.tscn +++ b/test_scene.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=11 format=3 uid="uid://dllug6vijj18o"] +[gd_scene load_steps=12 format=3 uid="uid://dllug6vijj18o"] [ext_resource type="PackedScene" uid="uid://cybm74xwbsivx" path="res://objects/canny_cat.tscn" id="1_8qiqb"] [ext_resource type="MeshLibrary" uid="uid://cbs170roel08g" path="res://assets/mesh_libraries/w1/w1_floors.meshlib" id="2_ohutf"] @@ -6,6 +6,7 @@ [ext_resource type="PackedScene" uid="uid://cdpgby3r6xe4n" path="res://objects/goal_post.tscn" id="4_71ems"] [ext_resource type="PackedScene" uid="uid://bfic5n608nc5j" path="res://objects/sand_pit.tscn" id="5_7n16u"] [ext_resource type="PackedScene" uid="uid://b4a8aif3iigdw" path="res://objects/skull.tscn" id="6_gpbt0"] +[ext_resource type="PackedScene" uid="uid://13qlrib2dk36" path="res://objects/waterman_pole.tscn" id="7_m8si3"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_akirf"] sky_top_color = Color(0.270389, 0.858166, 0.929253, 1) @@ -73,5 +74,9 @@ polygon = PackedVector2Array(0, -1, 1, -1, 3, 0, 3, 2, 2, 3, -1, 2, -2, 0) [node name="Boney" parent="." instance=ExtResource("6_gpbt0")] transform = Transform3D(0.707107, 0, -0.707107, 0, 1, 0, 0.707107, 0, 0.707107, 1.98854, 0, 1.02292) -[node name="Boney2" parent="." instance=ExtResource("6_gpbt0")] -transform = Transform3D(0.707107, 0, -0.707107, 0, 1, 0, 0.707107, 0, 0.707107, -1.34746, 0, 4.32965) +[node name="WatermanPole" parent="." instance=ExtResource("7_m8si3")] +transform = Transform3D(1, 0, 0, 0, 16, 0, 0, 0, 1, 0, 0, 0) +rise_speed = 8.0 +spin_speed = 12.5664 +offset = 1.0 +release_boost = 20.0