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() func _physics_process(_delta): 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")) Global.msg_debug("h_rotation:%s", [str(h_rotation)]) direction = direction.rotated(Vector3.UP,h_rotation).normalized() if character_component.gait == Global.GAIT.SPRINTING : character_component.add_movement_input(direction, character_component.current_movement_data.sprint_speed,character_component.current_movement_data.sprint_acceleration) elif character_component.gait == Global.GAIT.RUNNING: 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"): if character_component.stance != Global.STANCE.CROUCHING: character_component.stance = Global.STANCE.CROUCHING else: if character_component.stance != Global.STANCE.STANDING: character_component.stance = Global.STANCE.STANDING else: if Input.is_action_just_pressed("ui_crouch"): character_component.stance = Global.STANCE.STANDING if character_component.stance == Global.STANCE.CROUCHING else Global.STANCE.CROUCHING #------------------ Sprint ------------------# if UsingSprintToggle: if Input.is_action_just_pressed("ui_sprint"): 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 else: if Input.is_action_just_pressed("ui_sprint"): 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 if Input.is_action_just_released("ui_sprint"): 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: await get_tree().create_timer(0.4).timeout if character_component.gait == Global.GAIT.RUNNING: character_component.gait = Global.GAIT.WALKING #------------------ Input Aim ------------------# if Input.is_action_pressed("ui_aim"): if character_component.rotation_mode != Global.ROTATION_MODE.AIMING: previous_rotation_mode = character_component.rotation_mode character_component.rotation_mode = Global.ROTATION_MODE.AIMING else: if character_component.rotation_mode == Global.ROTATION_MODE.AIMING: character_component.rotation_mode = previous_rotation_mode #------------------ Jump ------------------#= if OnePressJump == true: if Input.is_action_just_pressed("ui_jump"): if character_component.stance != Global.STANCE.STANDING: character_component.stance = Global.STANCE.STANDING else: character_component.jump() else: if Input.is_action_pressed("ui_jump"): if character_component.stance != Global.STANCE.STANDING: character_component.stance = Global.STANCE.STANDING 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 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 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: 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 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 if character_component.rotation_mode == Global.ROTATION_MODE.VELOCITY_DIRECTION: if character_component.camera_root != null: if character_component.camera_root.view_mode == Global.VIEW_MODE.FIRST_PERSON: character_component.camera_root.view_mode = Global.VIEW_MODE.THIRD_PERSON