added most player movement states and started work on 'on foot'
This commit is contained in:
@@ -53,6 +53,9 @@ var last_ground_pos
|
||||
@export var BASE_FOV : float = 80
|
||||
@export var FOV_CHANGE = 1.5
|
||||
|
||||
## Movement
|
||||
var input_dir
|
||||
|
||||
## GUNS AND AMMO
|
||||
var gun : Node
|
||||
var holstered_gun_id : int
|
||||
@@ -174,103 +177,6 @@ func _input(event) -> void:
|
||||
func _physics_process(delta):
|
||||
|
||||
if !dead and !level_control.paused:
|
||||
|
||||
# Add the gravity.
|
||||
if is_on_floor():
|
||||
double_jump = true
|
||||
air_dash = level_control.gamemode.air_dash_max
|
||||
else:
|
||||
velocity.y += level_control.gamemode.gravity * delta
|
||||
if abs(velocity.y) >= .1:
|
||||
moving_fast = true
|
||||
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("jump"):
|
||||
if is_on_floor() and !is_climbing:
|
||||
velocity.y += level_control.gamemode.jump_velocity
|
||||
weapon_dip_pos += JUMP_WEAPON_DIP
|
||||
crouched = false
|
||||
elif wall_jump():
|
||||
velocity += Vector3(velocity.x * 5,12,velocity.z * 5)
|
||||
elif double_jump == true and !is_climbing:
|
||||
velocity.y += level_control.gamemode.jump_velocity
|
||||
double_jump = false
|
||||
|
||||
## HANDLE MOVEMENT DIRECTION
|
||||
var input_dir
|
||||
var direction
|
||||
#GetKB Input
|
||||
input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
#Get Joy Input
|
||||
input_dir += joypad_walk()
|
||||
if abs(Input.get_joy_axis(0,JOY_AXIS_LEFT_X)) > L_JOYSTICK_SENSITIVITY or abs(Input.get_joy_axis(0,JOY_AXIS_LEFT_Y)) > L_JOYSTICK_SENSITIVITY:
|
||||
direction = (self.transform.basis * Vector3(input_dir.x, 0, input_dir.y))
|
||||
else:
|
||||
direction = (self.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
|
||||
# Handle Sprint
|
||||
if Input.is_action_just_pressed("sprint") and !is_on_floor():
|
||||
if air_dash > 0:
|
||||
velocity.x += direction.x * level_control.gamemode.dash_speed
|
||||
velocity.z += direction.z * level_control.gamemode.dash_speed
|
||||
air_dash -= 1
|
||||
|
||||
if Input.is_action_pressed("move_left"):
|
||||
wall_ray_1.enabled = true
|
||||
else:
|
||||
wall_ray_1.enabled = false
|
||||
|
||||
if Input.is_action_pressed("move_right"):
|
||||
wall_ray_2.enabled = true
|
||||
else:
|
||||
wall_ray_2.enabled = false
|
||||
|
||||
if Input.is_action_just_pressed("crouch"):
|
||||
if crouched:
|
||||
if !crouch_check.is_colliding():
|
||||
crouched = !crouched
|
||||
recoil.add_recoil(Vector3(-.2,.03,.03),5,10)
|
||||
crouch_audio.play()
|
||||
else:
|
||||
recoil.add_recoil(Vector3(-.2,.03,.03),20,10)
|
||||
hit_head.play()
|
||||
else:
|
||||
crouched = !crouched
|
||||
recoil.add_recoil(Vector3(.2,0,0),5,10)
|
||||
if is_on_floor():
|
||||
crouch_audio.play()
|
||||
velocity += direction * 20
|
||||
else:
|
||||
velocity.y -= 25
|
||||
|
||||
#walking
|
||||
if is_on_floor() and !is_climbing:
|
||||
if direction:
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * GROUND_TRANSITION_SPEED)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * GROUND_TRANSITION_SPEED)
|
||||
else:
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5) + (direction.x * level_control.gamemode.dash_speed)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * 6.5) + (direction.z * level_control.gamemode.dash_speed)
|
||||
#ladder movement
|
||||
elif is_climbing and !is_on_floor():
|
||||
gravity = 0.0
|
||||
if direction:
|
||||
velocity.y = -direction.z * speed * .75
|
||||
velocity.x = direction.x * speed * .3
|
||||
else:
|
||||
velocity.y = lerp(velocity.y, -direction.z * speed, delta * 6.5)
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5)
|
||||
#movement in air
|
||||
else:
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * AIR_TRANSITION_SPEED)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * AIR_TRANSITION_SPEED)
|
||||
## Wall Running
|
||||
if wall_ray_1.is_colliding() or wall_ray_2.is_colliding():
|
||||
if abs(Vector2(velocity.x,velocity.z)) >= Vector2(5.0,5.0):
|
||||
velocity.y = clamp(velocity.y,-1,abs(velocity.y))
|
||||
air_dash = 1
|
||||
|
||||
# Head bob
|
||||
t_bob += delta * velocity.length() * float(is_on_floor())
|
||||
camera.transform.origin = _headbob(t_bob)
|
||||
@@ -333,11 +239,6 @@ func _physics_process(delta):
|
||||
if level_control.gamemode.stamina_regen == true:
|
||||
remaining_stamina = clamp(remaining_stamina + (delta * level_control.gamemode.stamina_gain/Engine.time_scale), 0, level_control.gamemode.max_stamina)
|
||||
|
||||
|
||||
# Reloading
|
||||
if Input.is_action_just_pressed("reload"):
|
||||
gun.reload()
|
||||
|
||||
if Input.is_action_pressed("inspect") and !gun.anim_player.is_playing():
|
||||
gun.anim_player.play("inspect")
|
||||
|
||||
@@ -349,12 +250,6 @@ func _physics_process(delta):
|
||||
flashlight_on = true
|
||||
flashlight_audio.play()
|
||||
|
||||
|
||||
# Shooting & fire modes
|
||||
if Input.is_action_pressed("shoot"):
|
||||
if gun != null:
|
||||
gun.shoot()
|
||||
|
||||
# Gun folding out of the way
|
||||
if gun_ray.is_colliding():
|
||||
var distance_to_wall = 1 - (gun_ray.global_position.distance_to(gun_ray.get_collision_point()) / abs(gun_ray.target_position.z))
|
||||
@@ -454,11 +349,25 @@ func _physics_process(delta):
|
||||
hold_item(delta)
|
||||
move_and_slide()
|
||||
crouch(delta)
|
||||
weapon_tilt(input_dir.x, delta)
|
||||
weapon_tilt(input_dir, delta)
|
||||
weapon_sway(delta)
|
||||
weapon_bob(velocity.length(), delta)
|
||||
|
||||
## MOVEMENT
|
||||
func movement_input():
|
||||
## HANDLE MOVEMENT DIRECTION
|
||||
var direction
|
||||
#GetKB Input
|
||||
input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
#Get Joy Input
|
||||
input_dir += joypad_walk()
|
||||
if abs(Input.get_joy_axis(0,JOY_AXIS_LEFT_X)) > L_JOYSTICK_SENSITIVITY or abs(Input.get_joy_axis(0,JOY_AXIS_LEFT_Y)) > L_JOYSTICK_SENSITIVITY:
|
||||
direction = (self.transform.basis * Vector3(input_dir.x, 0, input_dir.y))
|
||||
else:
|
||||
direction = (self.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
|
||||
return direction
|
||||
|
||||
func joypad_walk():
|
||||
# Joypad right stick look control
|
||||
var dir_out = Vector2(0,0)
|
||||
@@ -662,12 +571,13 @@ func focus_on_target():
|
||||
camera.attributes.dof_blur_far_enabled = false
|
||||
camera.attributes.dof_blur_near_enabled = false
|
||||
|
||||
func weapon_tilt(input_x, delta):
|
||||
if !ads:
|
||||
if weapon_holder:
|
||||
weapon_holder.rotation.z = lerp(weapon_holder.rotation.z, -input_x * weapon_rotation_amount * 10, 4 * delta)
|
||||
if camera:
|
||||
camera.rotation.z = lerp(camera.rotation.z, -input_x * HEAD_TILT_AMT, 5 * delta)
|
||||
func weapon_tilt(input, delta):
|
||||
if input:
|
||||
if !ads:
|
||||
if weapon_holder:
|
||||
weapon_holder.rotation.z = lerp(weapon_holder.rotation.z, -input.x * weapon_rotation_amount * 10, 4 * delta)
|
||||
if camera:
|
||||
camera.rotation.z = lerp(camera.rotation.z, -input.x * HEAD_TILT_AMT, 5 * delta)
|
||||
|
||||
func weapon_sway(delta):
|
||||
#aim gun at center screen
|
||||
|
||||
Reference in New Issue
Block a user