godot-third-person-basic-scene/addons/AMSG/Components/PlayerGameplayComponent.gd

233 lines
9.7 KiB
GDScript

extends CharacterMovementComponent
@export var networking_path : NodePath
@onready var networking = get_node(networking_path)
#####################################
#Controls Settings
@export var OnePressJump := false
@export var UsingSprintToggle := false
@export var UsingCrouchToggle := false
#####################################
@export var mouse_sensitvity : float = 0.01
var player_h : float = 0
var player_v : float = 0
var reconciliate_rotate_player_back:bool = false
var h_rotation :float
#var v_rotation :float
var direction := Vector3.FORWARD
var auto_up:bool = false
var previous_rotation_mode
func _physics_process(delta):
super._physics_process(delta)
# Debug()
if !networking.is_local_authority():
if input_is_moving:
if gait == Global.gait.sprinting:
add_movement_input(direction, current_movement_data.sprint_speed,current_movement_data.sprint_acceleration)
elif gait == Global.gait.running:
add_movement_input(direction, current_movement_data.run_speed,current_movement_data.run_acceleration)
else:
add_movement_input(direction, current_movement_data.walk_speed,current_movement_data.walk_acceleration)
else:
add_movement_input(direction,0,deacceleration)
return
#------------------ Input Movement ------------------#
h_rotation = camera_root.HObject.transform.basis.get_euler().y
#v_rotation = camera_root.VObject.transform.basis.get_euler().x
follow_camera = true
rotation_mode = Global.rotation_mode.velocity_direction
if Common.is_menu_visible():
add_movement_input(direction,0,deacceleration)
return
if Input.is_action_pressed("INPUT_ACTION_CAMERA_MOVE_PLAYER_MOUSE") && Input.is_action_pressed("INPUT_VIEW_CAMERA_MOVE_PLAYER_FOLLOW_MOUSE"):
direction = Vector3(0.0,
0.0 if is_flying == true else 0.0,
-1.0)
direction = direction.rotated(Vector3.UP,h_rotation).normalized()
if gait == Global.gait.sprinting :
add_movement_input(direction, current_movement_data.sprint_speed,current_movement_data.sprint_acceleration)
elif gait == Global.gait.running:
add_movement_input(direction, current_movement_data.run_speed,current_movement_data.run_acceleration)
else:
add_movement_input(direction, current_movement_data.walk_speed,current_movement_data.walk_acceleration)
elif Input.is_action_pressed("INPUT_ACTION_ROTATE_LEFT"):
rotate_in_place_X(+0.05)
elif Input.is_action_pressed("INPUT_ACTION_ROTATE_RIGHT"):
rotate_in_place_X(-0.05)
elif Input.is_action_pressed("INPUT_ACTION_FORWARD") || Input.is_action_pressed("INPUT_ACTION_BACK") || Input.is_action_pressed("INPUT_ACTION_RIGHT") || Input.is_action_pressed("INPUT_ACTION_LEFT") :
direction = Vector3(Input.get_action_strength("INPUT_ACTION_RIGHT") - Input.get_action_strength("INPUT_ACTION_LEFT"),
0.0 if is_flying == true else 0.0,
Input.get_action_strength("INPUT_ACTION_BACK") - Input.get_action_strength("INPUT_ACTION_FORWARD"))
direction = direction.rotated(Vector3.UP,h_rotation).normalized()
if gait == Global.gait.sprinting :
add_movement_input(direction, current_movement_data.sprint_speed,current_movement_data.sprint_acceleration)
elif gait == Global.gait.running:
add_movement_input(direction, current_movement_data.run_speed,current_movement_data.run_acceleration)
else:
add_movement_input(direction, current_movement_data.walk_speed,current_movement_data.walk_acceleration)
elif auto_up:
follow_camera = false
direction = Vector3(0.0,
0.0 if is_flying == true else 0.0,
1.0)
##direction = get_current_mesh() #direction.rotated(Vector3.UP,h_rotation).normalized()
direction = direction.rotated(Vector3.UP,get_current_mesh().y).normalized()
##direction = direction.rotated(get_current_mesh(),h_rotation).normalized()
#direction = direction.rotated(Vector3.UP,-get_current_mesh().y).normalized()
if gait == Global.gait.sprinting :
add_movement_input(direction, current_movement_data.sprint_speed,current_movement_data.sprint_acceleration)
elif gait == Global.gait.running:
add_movement_input(direction, current_movement_data.run_speed,current_movement_data.run_acceleration)
else:
add_movement_input(direction, current_movement_data.walk_speed,current_movement_data.walk_acceleration)
rotation_mode = Global.rotation_mode.keep_current
elif reconciliate_rotate_player_back:
reconciliate_rotate_player_back = rotate_in_place()
else:
add_movement_input(direction,0,deacceleration)
#------------------ Input Crouch ------------------#
if UsingCrouchToggle == false:
if Input.is_action_pressed("INPUT_ACTION_CROUCH"):
if stance != Global.stance.crouching:
stance = Global.stance.crouching
else:
if stance != Global.stance.standing:
stance = Global.stance.standing
else:
if Input.is_action_just_pressed("INPUT_ACTION_CROUCH"):
stance = Global.stance.standing if stance == Global.stance.crouching else Global.stance.crouching
#------------------ Sprint ------------------#
if UsingSprintToggle:
if Input.is_action_just_pressed("INPUT_ACTION_RUN"):
if gait == Global.gait.walking:
gait = Global.gait.running
elif gait == Global.gait.running:
gait = Global.gait.sprinting
elif gait == Global.gait.sprinting:
gait = Global.gait.walking
else:
if Input.is_action_just_pressed("INPUT_ACTION_RUN"):
if gait == Global.gait.walking:
gait = Global.gait.running
elif gait == Global.gait.running:
gait = Global.gait.sprinting
if Input.is_action_just_released("INPUT_ACTION_RUN"):
if gait == Global.gait.sprinting or gait == Global.gait.walking:
gait = Global.gait.walking
elif gait == Global.gait.running:
await get_tree().create_timer(0.4).timeout
if gait == Global.gait.running:
gait = Global.gait.walking
#------------------ Input Aim ------------------#
if Input.is_action_pressed("INPUT_ACTION_AIM"):
if rotation_mode != Global.rotation_mode.aiming:
previous_rotation_mode = rotation_mode
rotation_mode = Global.rotation_mode.aiming
else:
if rotation_mode == Global.rotation_mode.aiming:
rotation_mode = previous_rotation_mode
#------------------ Jump ------------------#=
if OnePressJump == true:
if Input.is_action_just_pressed("INPUT_ACTION_JUMP"):
if stance != Global.stance.standing:
stance = Global.stance.standing
else:
jump()
else:
if Input.is_action_pressed("INPUT_ACTION_JUMP"):
if stance != Global.stance.standing:
stance = Global.stance.standing
else:
jump()
#------------------ Look At ------------------#
match rotation_mode:
Global.rotation_mode.velocity_direction:
if input_is_moving:
ik_look_at(actual_velocity + Vector3(0.0,1.0,0.0))
Global.rotation_mode.looking_direction:
ik_look_at(camera_root.SpringArm.transform.basis.z * 2.0 + Vector3(0.0,1.5,0.0))
Global.rotation_mode.aiming:
ik_look_at(camera_root.SpringArm.transform.basis.z * 2.0 + Vector3(0.0,1.5,0.0))
#------------------ Interaction ------------------#
if Input.is_action_just_pressed("INPUT_ACTION_INTERACTION"):
camera_root.Camera.get_node("InteractionRaycast").Interact()
var view_changed_recently = false
func _input(event):
if Common.is_menu_visible():
return
#if event is InputEventMouseMotion:
if Input.is_action_pressed("INPUT_VIEW_CAMERA_MOVE_PLAYER_FOLLOW_MOUSE"):
reconciliate_rotate_player_back = true
# player_h += -event.relative.x * mouse_sensitvity
# player_v += -event.relative.y * mouse_sensitvity
# Common.msg_debug("player_h:" + str(player_h))
# if reconciliate_rotate_player_back:
# Common.msg_debug("h_rotation:" + str(h_rotation))
# pass
if Input.is_action_just_pressed("INPUT_ACTION_AUTO_UP"):
auto_up = !auto_up
Common.msg_debug(auto_up)
# if auto_up:
# rotation_mode = Global.rotation_mode.velocity_direction
# update_character_movement()
#------------------ Motion Warping test------------------#
if event.is_action_pressed("INPUT_ACTION_FIRE"):
anim_ref.active = false
get_node("../MotionWarping").add_sync_position(Vector3(4.762,1.574,-1.709),Vector3(0,PI,0),"kick_target",self,mesh_ref)
get_node("../AnimationPlayer").play("Kick")
await get_tree().create_timer(2.6).timeout
anim_ref.active = true
#------------------ Change Camera View ------------------#
if Input.is_action_just_released("INPUT_VIEW_SWITCH_CAMERA"):
if view_changed_recently == false:
view_changed_recently = true
camera_root.view_angle = camera_root.view_angle + 1 if camera_root.view_angle < 2 else 0
await get_tree().create_timer(0.3).timeout
view_changed_recently = false
else:
view_changed_recently = false
if Input.is_action_just_pressed("INPUT_VIEW_SWITCH_CAMERA"):
await get_tree().create_timer(0.2).timeout
if view_changed_recently == false:
camera_root.view_mode = camera_root.view_mode + 1 if camera_root.view_mode < 1 else 0
if camera_root.view_mode == Global.view_mode.first_person and networking.is_local_authority():
mesh_ref.visible = false
else:
mesh_ref.visible = true
view_changed_recently = true
if networking.is_local_authority():
if event.is_action_pressed("INPUT_DISPLAY_ENABLE_SDFGI"):
var postprocess = preload("res://PlayerB/Maps/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("INPUT_ACTION_RAGDOLL"):
ragdoll = true
if rotation_mode == Global.rotation_mode.velocity_direction:
if camera_root != null:
if camera_root.view_mode == Global.view_mode.first_person:
camera_root.view_mode = Global.view_mode.third_person
#func Debug():
# $Status/Label.text = "InputSpeed : %s" % input_velocity.length()
# $Status/Label2.text = "ActualSpeed : %s" % get_velocity().length()