generated from krampus/template-godot4
Focus controls when firing
This commit is contained in:
parent
42f59962f5
commit
e2996a373c
@ -1,6 +1,10 @@
|
||||
class_name CameraController extends Node3D
|
||||
|
||||
const PITCH_LIMIT := deg_to_rad(85.0)
|
||||
const FOCUS_SENSITIVITY := 0.2
|
||||
const FOCUS_ACCELERATION := 3
|
||||
|
||||
@onready var player: Player = owner
|
||||
|
||||
@onready var _target := Vector2(rotation.x, rotation.y)
|
||||
|
||||
@ -17,6 +21,11 @@ func camera_motion(motion: Vector2) -> void:
|
||||
var x_sensitivity: float = ProjectSettings.get_setting("game/config/input/mouse_sensitivity_x")
|
||||
var y_sensitivity: float = ProjectSettings.get_setting("game/config/input/mouse_sensitivity_y")
|
||||
var invert_pitch: bool = ProjectSettings.get_setting("game/config/input/invert_pitch")
|
||||
if player.firing:
|
||||
# Focus movement when firing
|
||||
# Game mechanic, should not be user-configurable.
|
||||
x_sensitivity = FOCUS_SENSITIVITY
|
||||
y_sensitivity = FOCUS_SENSITIVITY
|
||||
|
||||
_target.y -= deg_to_rad(motion.x * x_sensitivity)
|
||||
_target.x = clampf(
|
||||
@ -30,5 +39,7 @@ func _physics_process(_delta: float) -> void:
|
||||
var mouse_accel: float = (
|
||||
ProjectSettings.get_setting("game/config/input/mouse_acceleration") / 60.0
|
||||
)
|
||||
if player.firing:
|
||||
mouse_accel = FOCUS_ACCELERATION / 60.0
|
||||
rotation.y = lerp_angle(rotation.y, _target.y, mouse_accel)
|
||||
rotation.x = lerp_angle(rotation.x, _target.x, mouse_accel)
|
||||
|
@ -13,10 +13,11 @@ var gravity: Vector3 = (
|
||||
)
|
||||
|
||||
var selected_interactive: Interactive
|
||||
var firing := false
|
||||
|
||||
@onready var player_hud: PlayerHUD = %PlayerHUD
|
||||
|
||||
@onready var camera_pivot: Node3D = %CameraPivot
|
||||
@onready var camera_pivot: CameraController = %CameraPivot
|
||||
@onready var spray_muzzle: Marker3D = %SprayMuzzle
|
||||
@onready var interact_ray: RayCast3D = %InteractRay
|
||||
|
||||
@ -49,8 +50,10 @@ func _physics_process(delta: float) -> void:
|
||||
|
||||
if Input.is_action_pressed("fire"):
|
||||
get_spray().fire()
|
||||
firing = true
|
||||
else:
|
||||
get_spray().idle()
|
||||
firing = false
|
||||
|
||||
# Gravity
|
||||
if not is_on_floor():
|
||||
|
@ -3,7 +3,7 @@ extends Node3D
|
||||
signal cleared
|
||||
signal activated
|
||||
|
||||
const CLEAR_THRESHOLD := 2750
|
||||
const CLEAR_THRESHOLD := 2650
|
||||
|
||||
@export var enabled := false
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user