Shot setup

This commit is contained in:
Rob Kelly 2024-10-20 20:27:08 -06:00
parent cb176e1805
commit 828d89db33
8 changed files with 185 additions and 31 deletions

File diff suppressed because one or more lines are too long

View File

@ -88,6 +88,21 @@ camera_sprint={
"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":4194325,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
shot_zoom_in={
"deadzone": 0.5,
"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":4,"canceled":false,"pressed":false,"double_click":false,"script":null)
]
}
shot_zoom_out={
"deadzone": 0.5,
"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":5,"canceled":false,"pressed":false,"double_click":false,"script":null)
]
}
shot_accept={
"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":32,"key_label":0,"unicode":32,"echo":false,"script":null)
]
}
[layer_names]

View File

@ -1,7 +1,7 @@
class_name GameCamera extends CharacterBody3D
class_name FreeCamera extends CharacterBody3D
const SPRINT_MULT := 2.0
const PITCH_MAX := deg_to_rad(85.0)
const PITCH_LIMIT := deg_to_rad(85.0)
var base_speed: float = ProjectSettings.get_setting("game/config/controls/camera/free_camera_speed")
@ -35,8 +35,8 @@ func camera_motion(motion: Vector2) -> void:
_target.y = _target.y - deg_to_rad(motion.x * x_sensitivity)
_target.x = clampf(
_target.x - deg_to_rad(motion.y * y_sensitivity) * (-1 if invert_pitch else 1),
-PITCH_MAX,
PITCH_MAX,
-PITCH_LIMIT,
PITCH_LIMIT,
)
@ -47,7 +47,7 @@ func _physics_process(delta: float) -> void:
# Handle spatial movement
var xz_input := Input.get_vector("camera_left", "camera_right", "camera_forward", "camera_back")
var y_input := Input.get_vector("", "", "camera_down", "camera_up")
var y_input := Input.get_vector("camera_down", "camera_up", "camera_down", "camera_up")
var direction := (transform.basis * Vector3(xz_input.x, y_input.y, xz_input.y)).normalized()
var speed := base_speed

View File

@ -1,10 +1,10 @@
[gd_scene load_steps=3 format=3 uid="uid://dd17ce110sw6p"]
[ext_resource type="Script" path="res://src/player/game_camera.gd" id="1_3gm3q"]
[ext_resource type="Script" path="res://src/player/free_camera/free_camera.gd" id="1_3gm3q"]
[sub_resource type="SphereShape3D" id="SphereShape3D_wmusx"]
[node name="GameCamera" type="CharacterBody3D"]
[node name="FreeCamera" type="CharacterBody3D"]
script = ExtResource("1_3gm3q")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]

View File

@ -1,11 +0,0 @@
extends Node3D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass

View File

@ -1,6 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://cy7t2tc4y3b4"]
[ext_resource type="Script" path="res://src/player/shot_setup.gd" id="1_r6ei4"]
[node name="ShotSetup" type="Node3D"]
script = ExtResource("1_r6ei4")

View File

@ -0,0 +1,85 @@
class_name ShotSetup extends Node3D
const PITCH_MIN := deg_to_rad(-60.0)
const PITCH_MAX := deg_to_rad(-5.0)
const ZOOM_LENGTH := 0.1
const ZOOM_MIN := 1.0
const ZOOM_MAX := 12.0
enum Phase {
AIMING,
LATERAL,
POWER,
FINISHED,
}
var base_speed: float = ProjectSettings.get_setting("game/config/controls/camera/free_camera_speed")
var x_sensitivity: float = ProjectSettings.get_setting(
"game/config/controls/camera/x_axis_sensitivity"
)
var x_acceleration: float = ProjectSettings.get_setting(
"game/config/controls/camera/x_axis_acceleration"
)
var y_sensitivity: float = ProjectSettings.get_setting(
"game/config/controls/camera/y_axis_sensitivity"
)
var y_acceleration: float = ProjectSettings.get_setting(
"game/config/controls/camera/y_axis_acceleration"
)
var invert_pitch: bool = ProjectSettings.get_setting("game/config/controls/camera/invert_pitch")
var _phase: Phase = Phase.AIMING
@onready var direction: Node3D = %Direction
@onready var pitch: Node3D = %Pitch
@onready var camera: Camera3D = %Camera
@onready var camera_distance := camera.position.z:
set = _set_camera_distance
@onready var _target_rotation := Vector2(pitch.rotation.x, direction.rotation.y)
func _set_camera_distance(value: float) -> void:
var tween := get_tree().create_tween()
tween.tween_property(camera, "position", Vector3(0, 0, value), ZOOM_LENGTH).set_trans(
Tween.TRANS_SINE
)
camera_distance = value
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
elif event is InputEventMouseMotion:
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
camera_motion((event as InputEventMouseMotion).relative)
func camera_motion(motion: Vector2) -> void:
if _phase == Phase.AIMING:
# Can only control camera while aiming
_target_rotation.y = _target_rotation.y - deg_to_rad(motion.x * x_sensitivity)
_target_rotation.x = clampf(
_target_rotation.x - deg_to_rad(motion.y * y_sensitivity) * (-1 if invert_pitch else 1),
PITCH_MIN,
PITCH_MAX
)
func _physics_process(delta: float) -> void:
if _phase == Phase.AIMING:
# Camera zoom
if Input.is_action_just_pressed("shot_zoom_in"):
camera_distance = max(camera_distance - 1.0, ZOOM_MIN)
if Input.is_action_just_pressed("shot_zoom_out"):
camera_distance = min(camera_distance + 1.0, ZOOM_MAX)
# 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)

View File

@ -0,0 +1,72 @@
[gd_scene load_steps=4 format=3 uid="uid://cy7t2tc4y3b4"]
[ext_resource type="Script" path="res://src/player/shot_setup/shot_setup.gd" id="1_r6ei4"]
[sub_resource type="SphereMesh" id="SphereMesh_bvjn0"]
radius = 0.05
height = 0.1
[sub_resource type="CapsuleMesh" id="CapsuleMesh_5uovl"]
[node name="ShotSetup" type="Node3D"]
script = ExtResource("1_r6ei4")
[node name="BallMesh" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.1, 0)
mesh = SubResource("SphereMesh_bvjn0")
[node name="PlayerReference" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.212, 1, 0)
mesh = SubResource("CapsuleMesh_5uovl")
[node name="Direction" type="Node3D" parent="."]
unique_name_in_owner = true
[node name="Pitch" type="Node3D" parent="Direction"]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 0.907777, 0.419452, 0, -0.419452, 0.907777, 0, 0, 0)
[node name="Camera" type="Camera3D" parent="Direction/Pitch"]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 6)
[node name="ShotUI" type="Control" parent="."]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="ShotGauges" type="Control" parent="ShotUI"]
layout_mode = 1
anchor_left = 0.4
anchor_top = 0.3
anchor_right = 0.6
anchor_bottom = 0.7
offset_left = -20.0
offset_top = -20.0
offset_right = 20.0
offset_bottom = 20.0
grow_horizontal = 2
grow_vertical = 2
[node name="LateralGauge" type="Control" parent="ShotUI/ShotGauges"]
layout_mode = 1
anchors_preset = 12
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 0
[node name="ProgressBar" type="ProgressBar" parent="ShotUI/ShotGauges/LateralGauge"]
custom_minimum_size = Vector2(128, 32)
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
step = 1.0
show_percentage = false