generated from krampus/template-godot4
Player control lockouts
This commit is contained in:
parent
ecdedfc58c
commit
028b59cddb
@ -11,7 +11,7 @@ const FOCUS_ACCELERATION := 8
|
|||||||
|
|
||||||
func _unhandled_input(event: InputEvent) -> void:
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
if event is InputEventMouseMotion:
|
if event is InputEventMouseMotion:
|
||||||
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED and player.look_enabled:
|
||||||
camera_motion((event as InputEventMouseMotion).relative)
|
camera_motion((event as InputEventMouseMotion).relative)
|
||||||
elif event is InputEventMouseButton:
|
elif event is InputEventMouseButton:
|
||||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||||
|
@ -2,6 +2,11 @@ class_name Player extends CharacterBody3D
|
|||||||
|
|
||||||
#region Exported Properties
|
#region Exported Properties
|
||||||
|
|
||||||
|
@export_category("Status")
|
||||||
|
@export var movement_enabled := true
|
||||||
|
@export var activity_enabled := true
|
||||||
|
@export var look_enabled := true
|
||||||
|
|
||||||
@export_category("Movement")
|
@export_category("Movement")
|
||||||
@export_group("Speed")
|
@export_group("Speed")
|
||||||
@export var run_speed := 80.0
|
@export var run_speed := 80.0
|
||||||
@ -138,42 +143,47 @@ func _physics_process(delta: float) -> void:
|
|||||||
if interactive:
|
if interactive:
|
||||||
interactive.select()
|
interactive.select()
|
||||||
|
|
||||||
# World interaction
|
if activity_enabled:
|
||||||
if interactive and Input.is_action_just_pressed("interact"):
|
# World interaction
|
||||||
interactive.activate()
|
if interactive and Input.is_action_just_pressed("interact"):
|
||||||
|
interactive.activate()
|
||||||
|
|
||||||
# Tool selection
|
# Tool selection
|
||||||
if Input.is_action_just_pressed("select_next_tool"):
|
if Input.is_action_just_pressed("select_next_tool"):
|
||||||
tool_mount.set_active_relative(1)
|
tool_mount.set_active_relative(1)
|
||||||
elif Input.is_action_just_pressed("select_prev_tool"):
|
elif Input.is_action_just_pressed("select_prev_tool"):
|
||||||
tool_mount.set_active_relative(-1)
|
tool_mount.set_active_relative(-1)
|
||||||
elif Input.is_action_just_pressed("select_point_spray"):
|
elif Input.is_action_just_pressed("select_point_spray"):
|
||||||
tool_mount.set_active(point_spray)
|
tool_mount.set_active(point_spray)
|
||||||
elif Input.is_action_just_pressed("select_wide_spray"):
|
elif Input.is_action_just_pressed("select_wide_spray"):
|
||||||
tool_mount.set_active(wide_spray)
|
tool_mount.set_active(wide_spray)
|
||||||
elif Input.is_action_just_pressed("select_brush"):
|
elif Input.is_action_just_pressed("select_brush"):
|
||||||
tool_mount.set_active(toothbrush)
|
tool_mount.set_active(toothbrush)
|
||||||
|
|
||||||
# Tool use
|
# Tool use
|
||||||
if Input.is_action_pressed("fire"):
|
if Input.is_action_pressed("fire"):
|
||||||
get_tool().fire()
|
get_tool().fire()
|
||||||
firing = true
|
firing = true
|
||||||
else:
|
|
||||||
get_tool().idle()
|
|
||||||
firing = false
|
|
||||||
|
|
||||||
if Input.is_action_just_pressed("switch_mode"):
|
|
||||||
get_tool().switch_mode()
|
|
||||||
|
|
||||||
# Two sneaking modes -- hold and toggle
|
|
||||||
if Game.settings.hold_to_sneak:
|
|
||||||
if Input.is_action_pressed("sneak"):
|
|
||||||
crouch()
|
|
||||||
else:
|
else:
|
||||||
uncrouch()
|
get_tool().idle()
|
||||||
else:
|
firing = false
|
||||||
if Input.is_action_just_pressed("sneak"):
|
|
||||||
toggle_crouch()
|
if Input.is_action_just_pressed("switch_mode"):
|
||||||
|
get_tool().switch_mode()
|
||||||
|
|
||||||
|
# Two sneaking modes -- hold and toggle
|
||||||
|
if Game.settings.hold_to_sneak:
|
||||||
|
if Input.is_action_pressed("sneak"):
|
||||||
|
crouch()
|
||||||
|
else:
|
||||||
|
uncrouch()
|
||||||
|
else:
|
||||||
|
if Input.is_action_just_pressed("sneak"):
|
||||||
|
toggle_crouch()
|
||||||
|
|
||||||
|
# Jumping
|
||||||
|
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||||
|
velocity.y = jump_force
|
||||||
|
|
||||||
if is_on_floor():
|
if is_on_floor():
|
||||||
if not _was_on_floor and not sneaking:
|
if not _was_on_floor and not sneaking:
|
||||||
@ -184,14 +194,13 @@ func _physics_process(delta: float) -> void:
|
|||||||
velocity += gravity * delta
|
velocity += gravity * delta
|
||||||
|
|
||||||
# Input movement
|
# Input movement
|
||||||
var input_dir := Input.get_vector("move_left", "move_right", "move_forward", "move_back")
|
if movement_enabled:
|
||||||
var rel_input := input_dir.rotated(-camera_pivot.global_rotation.y)
|
var input_dir := Input.get_vector("move_left", "move_right", "move_forward", "move_back")
|
||||||
var direction := Vector3(rel_input.x, 0, rel_input.y).normalized()
|
var rel_input := input_dir.rotated(-camera_pivot.global_rotation.y)
|
||||||
var movement := direction * get_speed() * delta
|
var direction := Vector3(rel_input.x, 0, rel_input.y).normalized()
|
||||||
velocity.x += movement.x
|
var movement := direction * get_speed() * delta
|
||||||
velocity.z += movement.z
|
velocity.x += movement.x
|
||||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
velocity.z += movement.z
|
||||||
velocity.y = jump_force
|
|
||||||
|
|
||||||
# Friction
|
# Friction
|
||||||
var friction := get_friction()
|
var friction := get_friction()
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
class_name World extends Node
|
class_name World extends Node
|
||||||
## Access and flow control for the game world.
|
## Access and flow control for the game world.
|
||||||
|
|
||||||
|
@export var pause_enabled := true
|
||||||
|
|
||||||
@export var spook_manager: SpookManager
|
@export var spook_manager: SpookManager
|
||||||
|
|
||||||
@export_category("Game Scenes")
|
@export_category("Game Scenes")
|
||||||
@ -20,7 +22,7 @@ func _ready() -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _unhandled_input(event: InputEvent) -> void:
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
if event.is_action_pressed("pause"):
|
if event.is_action_pressed("pause") and pause_enabled:
|
||||||
pause()
|
pause()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user