Shot setup loops advances to finish after ball comes to rest.

This commit is contained in:
Rob Kelly 2024-11-04 15:16:32 -07:00
parent ecc425f10d
commit b0551df391
5 changed files with 97 additions and 90 deletions

File diff suppressed because one or more lines are too long

View File

@ -121,6 +121,7 @@ shot_accept={
[physics]
3d/default_angular_damp=5.0
3d/sleep_threshold_angular=0.3
[rendering]

View File

@ -17,6 +17,7 @@ const ZOOM_MIN := 1.0
const ZOOM_MAX := 12.0
const ARROW_ACCELERATION := 8.0
const PLAYER_ACCELERATION := 1.0
const FREE_CAM_RETURN_TIME := 0.618
const BALL_RETURN_TIME := 0.618
@ -62,7 +63,8 @@ var _returning_free_camera := false
@onready var pitch: Node3D = %Pitch
@onready var zoom: Node3D = %Zoom
@onready var camera: Camera3D = %Camera
@onready var tracking_camera: TrackingCamera = %TrackingCamera
@onready var player_pivot: Node3D = %PlayerPivot
@onready var shot_animation: AnimationPlayer = %ShotAnimation
@ -136,6 +138,7 @@ func take_shot() -> void:
func _on_phase_change(new_phase: Phase) -> void:
match new_phase:
Phase.AIM:
arrow_animation.play("show")
camera.make_current()
power_bar.hide()
curve_bar.hide()
@ -157,6 +160,11 @@ func _on_phase_change(new_phase: Phase) -> void:
shot_animation.play("shoot")
arrow_animation.play("hide")
take_shot()
Phase.FINISHED:
power_bar.hide()
curve_bar.hide()
end_shot_track()
travel_to_ball()
func insert_free_cam() -> void:
@ -193,26 +201,41 @@ func return_ball() -> void:
)
func travel_to_ball() -> void:
physics_ball.freeze = true
global_position = physics_ball.global_position
physics_ball.global_transform = ball_point.global_transform
func start_shot_track() -> void:
tracking_camera.make_current()
tracking_camera.active = true
#tracking_camera.make_current()
#tracking_camera.active = true
var orbital_cam := OrbitalCamera.create(physics_ball)
orbital_cam.rotation.y = randf_range(0.0, TAU)
add_sibling(orbital_cam)
func end_shot_track() -> void:
camera.make_current()
tracking_camera.active = false
#tracking_camera.active = false
func _process(delta: float) -> void:
## Visual updates
# Rotation
direction.rotation.y = lerp_angle(
direction.rotation.y, _target_rotation.y, delta * x_acceleration
)
pitch.rotation.x = lerp_angle(pitch.rotation.x, _target_rotation.x, delta * y_acceleration)
# Arrow lags behind camera control
arrow.rotation.y = lerp_angle(arrow.rotation.y, _target_rotation.y, delta * ARROW_ACCELERATION)
# Player lags further behind
player_pivot.rotation.y = lerp_angle(
player_pivot.rotation.y, _target_rotation.y, delta * PLAYER_ACCELERATION
)
# Input Handling
## Input Handling
if control_disabled:
if Input.is_action_just_pressed("camera_cancel"):
if is_instance_valid(_free_camera) and not _returning_free_camera:
@ -269,16 +292,11 @@ func _process(delta: float) -> void:
if driving_range and Input.is_action_just_pressed("shot_accept"):
phase = Phase.AIM
return_ball()
Phase.FINISHED:
# TODO: hand over to next player where appropriate
phase = Phase.AIM
func _on_physics_ball_body_entered(body: Node) -> void:
print("BONK! ", body.name)
print("Rotation: ", physics_ball.rotation_degrees)
print(
"Linear velocity: ",
physics_ball.linear_velocity,
" (",
physics_ball.linear_velocity.length(),
")"
)
print("Angular velocity: ", physics_ball.angular_velocity)
func _on_physics_ball_sleeping_state_changed() -> void:
if physics_ball.sleeping and phase == Phase.SHOT:
phase = Phase.FINISHED

View File

@ -1,9 +1,8 @@
[gd_scene load_steps=22 format=3 uid="uid://cy7t2tc4y3b4"]
[gd_scene load_steps=21 format=3 uid="uid://cy7t2tc4y3b4"]
[ext_resource type="Script" path="res://src/player/shot_setup/shot_setup.gd" id="1_r6ei4"]
[ext_resource type="PackedScene" uid="uid://dfttci386ohip" path="res://src/player/physics_ball/physics_ball.tscn" id="2_1i5j5"]
[ext_resource type="PackedScene" uid="uid://c2k88ns0h5ie1" path="res://src/ui/arrow.tscn" id="2_s70wl"]
[ext_resource type="PackedScene" uid="uid://ceu57tasi270s" path="res://src/player/tracking_camera/tracking_camera.tscn" id="3_7jqfy"]
[sub_resource type="CapsuleMesh" id="CapsuleMesh_5uovl"]
@ -174,6 +173,56 @@ _data = {
"shoot": SubResource("Animation_e65hh")
}
[sub_resource type="Animation" id="Animation_3xds6"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [false]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:visible_ratio")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [1.0]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath(".:rotation")
tracks/2/interp = 3
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [7.31612e-10]
}
tracks/3/type = "bezier"
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/path = NodePath(".:anchor_top")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/keys = {
"handle_modes": PackedInt32Array(0),
"points": PackedFloat32Array(0.5, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0)
}
[sub_resource type="Animation" id="Animation_cwotn"]
resource_name = "display"
length = 2.4
@ -226,56 +275,6 @@ tracks/3/keys = {
"times": PackedFloat32Array(0, 2, 2.4)
}
[sub_resource type="Animation" id="Animation_3xds6"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [false]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:visible_ratio")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [1.0]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath(".:rotation")
tracks/2/interp = 3
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [7.31612e-10]
}
tracks/3/type = "bezier"
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/path = NodePath(".:anchor_top")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/keys = {
"handle_modes": PackedInt32Array(0),
"points": PackedFloat32Array(0.5, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0)
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_2a0gn"]
_data = {
"RESET": SubResource("Animation_3xds6"),
@ -364,13 +363,14 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.2, 0)
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0)
freeze = true
contact_monitor = true
max_contacts_reported = 3
[node name="PlayerReference" type="MeshInstance3D" parent="."]
[node name="PlayerPivot" type="Node3D" parent="."]
unique_name_in_owner = true
[node name="PlayerRef" type="MeshInstance3D" parent="PlayerPivot"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.212, 1, 0)
mesh = SubResource("CapsuleMesh_5uovl")
skeleton = NodePath("../..")
[node name="Direction" type="Node3D" parent="."]
unique_name_in_owner = true
@ -401,10 +401,6 @@ unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 2.98023e-08, 0, -2.98023e-08, 1, 0, 0, 0)
current = true
[node name="TrackingCamera" parent="Direction/Elevation/Pitch/Zoom/Camera" node_paths=PackedStringArray("target") instance=ExtResource("3_7jqfy")]
unique_name_in_owner = true
target = NodePath("../../../../../../BallPoint/PhysicsBall")
[node name="Arrow" type="Node3D" parent="."]
unique_name_in_owner = true
transform = Transform3D(0.001, 0, 0, 0, 0.000707107, 0.000707107, 0, -0.000707107, 0.000707107, 0, 0.1, 0)
@ -451,6 +447,7 @@ offset_right = 350.0
offset_bottom = -63.6
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
theme_override_colors/font_shadow_color = Color(0, 0, 0, 1)
theme_override_constants/shadow_offset_y = 2
theme_override_constants/shadow_offset_x = 3
@ -467,15 +464,6 @@ libraries = {
"": SubResource("AnimationLibrary_2a0gn")
}
[node name="Feedback" type="Control" parent="ShotUI"]
layout_mode = 1
anchor_left = 0.5
anchor_top = 0.3
anchor_right = 0.5
anchor_bottom = 0.3
grow_horizontal = 2
grow_vertical = 2
[node name="ShotGauges" type="Control" parent="ShotUI"]
layout_mode = 1
anchor_left = 0.4
@ -556,4 +544,4 @@ libraries = {
[node name="GaugeFlasher" type="AnimationPlayer" parent="ShotUI/ShotGauges"]
unique_name_in_owner = true
[connection signal="body_entered" from="BallPoint/PhysicsBall" to="." method="_on_physics_ball_body_entered"]
[connection signal="sleeping_state_changed" from="BallPoint/PhysicsBall" to="." method="_on_physics_ball_sleeping_state_changed"]

View File

@ -6,7 +6,7 @@ const POSITION_ACCELERATION := 4.0
@export var target: Node3D
@export var active: bool = false
@export var active := false
@export var min_distance := 0.5
@export var max_distance := 3.0