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:
|
||||
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)
|
||||
elif event is InputEventMouseButton:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
@ -2,6 +2,11 @@ class_name Player extends CharacterBody3D
|
||||
|
||||
#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_group("Speed")
|
||||
@export var run_speed := 80.0
|
||||
@ -138,6 +143,7 @@ func _physics_process(delta: float) -> void:
|
||||
if interactive:
|
||||
interactive.select()
|
||||
|
||||
if activity_enabled:
|
||||
# World interaction
|
||||
if interactive and Input.is_action_just_pressed("interact"):
|
||||
interactive.activate()
|
||||
@ -175,6 +181,10 @@ func _physics_process(delta: float) -> void:
|
||||
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 not _was_on_floor and not sneaking:
|
||||
# just landed
|
||||
@ -184,14 +194,13 @@ func _physics_process(delta: float) -> void:
|
||||
velocity += gravity * delta
|
||||
|
||||
# Input movement
|
||||
if movement_enabled:
|
||||
var input_dir := Input.get_vector("move_left", "move_right", "move_forward", "move_back")
|
||||
var rel_input := input_dir.rotated(-camera_pivot.global_rotation.y)
|
||||
var direction := Vector3(rel_input.x, 0, rel_input.y).normalized()
|
||||
var movement := direction * get_speed() * delta
|
||||
velocity.x += movement.x
|
||||
velocity.z += movement.z
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
velocity.y = jump_force
|
||||
|
||||
# Friction
|
||||
var friction := get_friction()
|
||||
|
@ -1,6 +1,8 @@
|
||||
class_name World extends Node
|
||||
## Access and flow control for the game world.
|
||||
|
||||
@export var pause_enabled := true
|
||||
|
||||
@export var spook_manager: SpookManager
|
||||
|
||||
@export_category("Game Scenes")
|
||||
@ -20,7 +22,7 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("pause"):
|
||||
if event.is_action_pressed("pause") and pause_enabled:
|
||||
pause()
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user