bazar_alea/client/player/PlayerController.gd

174 lines
7.8 KiB
GDScript3
Raw Normal View History

2023-11-14 21:41:08 +00:00
extends Node
class_name PlayerController
#####################################
#Controls Settings
@export var OnePressJump := false
@export var UsingSprintToggle := false
@export var UsingCrouchToggle := false
#####################################
@export var character_component : PlayerGameplayComponent
@export var networking : PlayerNetworkingComponent
var controls_the_possessed_character:bool=false
var peer_id:int
var inputs :int
var input_vector :Vector2
var h_rotation :float
#var v_rotation :float
var previous_rotation_mode
var direction := Vector3.ZERO
@export var mouse_sensitivity : float = 0.01
func _ready():
#Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
possess_character(character_component,true)
func possess_character(p_character_component:CharacterMovementComponent,control:bool):
if character_component:
character_component.camera_root.Camera.current = false
controls_the_possessed_character = control
character_component = p_character_component
character_component.camera_root.Camera.current = networking.is_local_authority()
2023-11-19 19:41:38 +00:00
func _physics_process(_delta):
2023-11-14 21:41:08 +00:00
if !networking.is_local_authority():
return
#------------------ Input Movement ------------------#
h_rotation = character_component.camera_root.HObject.transform.basis.get_euler().y
var v_rotation = character_component.camera_root.VObject.transform.basis.get_euler().x
if Input.is_action_pressed("ui_up") || Input.is_action_pressed("ui_down") || Input.is_action_pressed("ui_right") || Input.is_action_pressed("ui_left") :
direction = Vector3(Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left"),
remap(v_rotation,-PI/2,PI/2,-1.0,1.0) if character_component.is_flying == true else 0.0,
Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up"))
direction = direction.rotated(Vector3.UP,h_rotation).normalized()
2023-11-24 23:00:05 +00:00
if character_component.gait == Global.GAIT.SPRINTING :
2023-11-14 21:41:08 +00:00
character_component.add_movement_input(direction, character_component.current_movement_data.sprint_speed,character_component.current_movement_data.sprint_acceleration)
2023-11-24 23:00:05 +00:00
elif character_component.gait == Global.GAIT.RUNNING:
2023-11-14 21:41:08 +00:00
character_component.add_movement_input(direction, character_component.current_movement_data.run_speed,character_component.current_movement_data.run_acceleration)
else:
character_component.add_movement_input(direction, character_component.current_movement_data.walk_speed,character_component.current_movement_data.walk_acceleration)
else:
direction = Vector3.ZERO
character_component.add_movement_input()
#------------------ Input Crouch ------------------#
if UsingCrouchToggle == false:
if Input.is_action_pressed("ui_crouch"):
2023-11-24 23:00:05 +00:00
if character_component.stance != Global.STANCE.CROUCHING:
character_component.stance = Global.STANCE.CROUCHING
2023-11-14 21:41:08 +00:00
else:
2023-11-24 23:00:05 +00:00
if character_component.stance != Global.STANCE.STANDING:
character_component.stance = Global.STANCE.STANDING
2023-11-14 21:41:08 +00:00
else:
if Input.is_action_just_pressed("ui_crouch"):
2023-11-24 23:00:05 +00:00
character_component.stance = Global.STANCE.STANDING if character_component.stance == Global.STANCE.CROUCHING else Global.STANCE.CROUCHING
2023-11-14 21:41:08 +00:00
#------------------ Sprint ------------------#
if UsingSprintToggle:
if Input.is_action_just_pressed("ui_sprint"):
2023-11-24 23:00:05 +00:00
if character_component.gait == Global.GAIT.WALKING:
character_component.gait = Global.GAIT.RUNNING
elif character_component.gait == Global.GAIT.RUNNING:
character_component.gait = Global.GAIT.SPRINTING
elif character_component.gait == Global.GAIT.SPRINTING:
character_component.gait = Global.GAIT.WALKING
2023-11-14 21:41:08 +00:00
else:
if Input.is_action_just_pressed("ui_sprint"):
2023-11-24 23:00:05 +00:00
if character_component.gait == Global.GAIT.WALKING:
character_component.gait = Global.GAIT.RUNNING
elif character_component.gait == Global.GAIT.RUNNING:
character_component.gait = Global.GAIT.SPRINTING
2023-11-14 21:41:08 +00:00
if Input.is_action_just_released("ui_sprint"):
2023-11-24 23:00:05 +00:00
if character_component.gait == Global.GAIT.SPRINTING or character_component.gait == Global.GAIT.WALKING:
character_component.gait = Global.GAIT.WALKING
elif character_component.gait == Global.GAIT.RUNNING:
2023-11-14 21:41:08 +00:00
await get_tree().create_timer(0.4).timeout
2023-11-24 23:00:05 +00:00
if character_component.gait == Global.GAIT.RUNNING:
character_component.gait = Global.GAIT.WALKING
2023-11-14 21:41:08 +00:00
#------------------ Input Aim ------------------#
if Input.is_action_pressed("ui_aim"):
2023-11-24 23:00:05 +00:00
if character_component.rotation_mode != Global.ROTATION_MODE.AIMING:
2023-11-14 21:41:08 +00:00
previous_rotation_mode = character_component.rotation_mode
2023-11-24 23:00:05 +00:00
character_component.rotation_mode = Global.ROTATION_MODE.AIMING
2023-11-14 21:41:08 +00:00
else:
2023-11-24 23:00:05 +00:00
if character_component.rotation_mode == Global.ROTATION_MODE.AIMING:
2023-11-14 21:41:08 +00:00
character_component.rotation_mode = previous_rotation_mode
#------------------ Jump ------------------#=
if OnePressJump == true:
if Input.is_action_just_pressed("ui_jump"):
2023-11-24 23:00:05 +00:00
if character_component.stance != Global.STANCE.STANDING:
character_component.stance = Global.STANCE.STANDING
2023-11-14 21:41:08 +00:00
else:
character_component.jump()
else:
if Input.is_action_pressed("ui_jump"):
2023-11-24 23:00:05 +00:00
if character_component.stance != Global.STANCE.STANDING:
character_component.stance = Global.STANCE.STANDING
2023-11-14 21:41:08 +00:00
else:
character_component.jump()
#------------------ Interaction ------------------#
if Input.is_action_just_pressed("ui_interaction"):
character_component.camera_root.Camera.get_node("InteractionRaycast").Interact()
var view_changed_recently = false
func _input(event):
if !networking.is_local_authority():
return
if Input.is_action_pressed("ui_rotate_player"):
if event is InputEventMouseMotion:
if !character_component or !controls_the_possessed_character:
return
character_component.camera_root.camera_h += -event.relative.x * mouse_sensitivity
character_component.camera_root.camera_v += -event.relative.y * mouse_sensitivity
#------------------ Motion Warping test------------------#
if event.is_action_pressed("ui_fire"):
character_component.anim_ref.active = false
get_node("../MotionWarping").add_sync_position(Vector3(4.762,1.574,-1.709),Vector3(0,PI,0),"kick_target",self,character_component.mesh_ref)
get_node("../AnimationPlayer").play("Kick")
await get_tree().create_timer(2.6).timeout
character_component.anim_ref.active = true
#------------------ Change Camera View ------------------#
if Input.is_action_just_released("ui_switch_camera_view"):
if view_changed_recently == false:
view_changed_recently = true
2023-11-19 19:41:38 +00:00
character_component.camera_root.view_angle = (character_component.camera_root.view_angle + 1) as Global.VIEW_ANGLE if character_component.camera_root.view_angle < 2 else 0 as Global.VIEW_ANGLE
2023-11-14 21:41:08 +00:00
await get_tree().create_timer(0.3).timeout
view_changed_recently = false
else:
view_changed_recently = false
if Input.is_action_just_pressed("ui_switch_camera_view"):
await get_tree().create_timer(0.2).timeout
if view_changed_recently == false:
2023-11-19 19:41:38 +00:00
character_component.camera_root.view_mode = (character_component.camera_root.view_mode + 1) as Global.VIEW_MODE if character_component.camera_root.view_mode < 1 else 0 as Global.VIEW_MODE
2023-11-14 21:41:08 +00:00
view_changed_recently = true
if networking.is_local_authority():
if event.is_action_pressed("ui_enable_sdfgi"):
var postprocess = preload("res://defaults/default_env.tres")
postprocess.sdfgi_enabled = not postprocess.sdfgi_enabled
postprocess.ssil_enabled = not postprocess.ssil_enabled
postprocess.ssao_enabled = not postprocess.ssao_enabled
postprocess.ssr_enabled = not postprocess.ssr_enabled
postprocess.glow_enabled = not postprocess.glow_enabled
if event.is_action_pressed("ui_ragdoll"):
character_component.ragdoll = true
2023-11-24 23:00:05 +00:00
if character_component.rotation_mode == Global.ROTATION_MODE.VELOCITY_DIRECTION:
2023-11-14 21:41:08 +00:00
if character_component.camera_root != null:
2023-11-24 23:00:05 +00:00
if character_component.camera_root.view_mode == Global.VIEW_MODE.FIRST_PERSON:
character_component.camera_root.view_mode = Global.VIEW_MODE.THIRD_PERSON