added most player movement states and started work on 'on foot'
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
[gd_scene load_steps=38 format=3 uid="uid://drwae3loscbw7"]
|
[gd_scene load_steps=39 format=3 uid="uid://drwae3loscbw7"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://bieeh1iro4ji1" path="res://scripts/player.gd" id="1_x7wms"]
|
[ext_resource type="Script" uid="uid://bieeh1iro4ji1" path="res://scripts/player.gd" id="1_x7wms"]
|
||||||
[ext_resource type="Script" uid="uid://csju024nerln6" path="res://scripts/StateMachine.gd" id="2_irwor"]
|
[ext_resource type="Script" uid="uid://csju024nerln6" path="res://scripts/StateMachine.gd" id="2_irwor"]
|
||||||
[ext_resource type="Script" uid="uid://s2nes6cthron" path="res://scripts/recoil.gd" id="3_405jc"]
|
[ext_resource type="Script" uid="uid://s2nes6cthron" path="res://scripts/recoil.gd" id="3_405jc"]
|
||||||
|
[ext_resource type="Script" uid="uid://o7g6oowyn6pe" path="res://scripts/player_on_foot.gd" id="3_ib4e7"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cknftvqq8rbrm" path="res://assets/Textures/Cookie_tutorial_texture_flashlight.png" id="4_x670l"]
|
[ext_resource type="Texture2D" uid="uid://cknftvqq8rbrm" path="res://assets/Textures/Cookie_tutorial_texture_flashlight.png" id="4_x670l"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dqgtnykkbngem" path="res://assets/weapon_select.tscn" id="5_bvbcl"]
|
[ext_resource type="PackedScene" uid="uid://dqgtnykkbngem" path="res://assets/weapon_select.tscn" id="5_bvbcl"]
|
||||||
[ext_resource type="PackedScene" uid="uid://br882tlh3cfwu" path="res://hud.tscn" id="5_yenaw"]
|
[ext_resource type="PackedScene" uid="uid://br882tlh3cfwu" path="res://hud.tscn" id="5_yenaw"]
|
||||||
@@ -135,8 +136,28 @@ script = ExtResource("1_x7wms")
|
|||||||
SENSITIVITY = 0.008
|
SENSITIVITY = 0.008
|
||||||
weapon_holder = NodePath("Head/Recoil/Camera3D/WeaponHolder")
|
weapon_holder = NodePath("Head/Recoil/Camera3D/WeaponHolder")
|
||||||
|
|
||||||
[node name="States" type="Node" parent="."]
|
[node name="States" type="Node" parent="." node_paths=PackedStringArray("player_character", "initial_state")]
|
||||||
script = ExtResource("2_irwor")
|
script = ExtResource("2_irwor")
|
||||||
|
player_character = NodePath("..")
|
||||||
|
initial_state = NodePath("On Foot")
|
||||||
|
|
||||||
|
[node name="On Foot" type="Node" parent="States"]
|
||||||
|
script = ExtResource("3_ib4e7")
|
||||||
|
metadata/_custom_type_script = "uid://dk0vg5btak80a"
|
||||||
|
|
||||||
|
[node name="Crouched" type="Node" parent="States"]
|
||||||
|
|
||||||
|
[node name="Jumping" type="Node" parent="States"]
|
||||||
|
|
||||||
|
[node name="Wall Running" type="Node" parent="States"]
|
||||||
|
|
||||||
|
[node name="Ground Pound" type="Node" parent="States"]
|
||||||
|
|
||||||
|
[node name="Knocked" type="Node" parent="States"]
|
||||||
|
|
||||||
|
[node name="Stunned" type="Node" parent="States"]
|
||||||
|
|
||||||
|
[node name="On Ladder" type="Node" parent="States"]
|
||||||
|
|
||||||
[node name="HealthIndicator" type="ColorRect" parent="."]
|
[node name="HealthIndicator" type="ColorRect" parent="."]
|
||||||
material = SubResource("CanvasItemMaterial_l5ga0")
|
material = SubResource("CanvasItemMaterial_l5ga0")
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ config_version=5
|
|||||||
|
|
||||||
config/name="First Person Test"
|
config/name="First Person Test"
|
||||||
config/tags=PackedStringArray("fps")
|
config/tags=PackedStringArray("fps")
|
||||||
run/main_scene="uid://f7e0v1r6ra6c"
|
run/main_scene="uid://cfaydhd6u5bmb"
|
||||||
config/features=PackedStringArray("4.4", "Forward Plus")
|
config/features=PackedStringArray("4.4", "Forward Plus")
|
||||||
config/icon="uid://6svuq1l83al5"
|
config/icon="uid://6svuq1l83al5"
|
||||||
|
|
||||||
|
|||||||
@@ -1,91 +1,14 @@
|
|||||||
extends State
|
extends State
|
||||||
class_name PlayerState
|
class_name PlayerState
|
||||||
|
|
||||||
@export var character: CharacterBody3D
|
@export var move_speed: float = 12
|
||||||
@export var move_speed: float = 3
|
@export var move_transition_speed : float = 7
|
||||||
@export var body_turn_speed: float = 3
|
|
||||||
@export var head_turn_speed: float = 6.0
|
@onready var player_character = get_parent().player_character
|
||||||
@export var can_see: bool = true # indicates whether the character is able to see things in the state
|
|
||||||
@export var poi_investigate: bool = false
|
|
||||||
@export var poi_change_to_search: bool = false
|
|
||||||
@export var poi_update_waypoint_immediately: bool = false
|
|
||||||
|
|
||||||
var move_target
|
var move_target
|
||||||
var look_target
|
var look_target
|
||||||
|
|
||||||
func character_has_target():
|
func standard_movement(delta):
|
||||||
if character.player_last_seen != null:
|
player_character.velocity.x = lerp(player_character.velocity.x, player_character.movement_input().x * move_speed,delta * move_transition_speed)
|
||||||
return true
|
player_character.velocity.z = lerp(player_character.velocity.z, player_character.movement_input().z * move_speed,delta * move_transition_speed)
|
||||||
if character.point_of_interest != null:
|
|
||||||
return true
|
|
||||||
return false
|
|
||||||
|
|
||||||
func update_move_target():
|
|
||||||
if character.player_last_seen != null:
|
|
||||||
return character.player_last_seen
|
|
||||||
elif character.point_of_interest != null:
|
|
||||||
return character.point_of_interest["point"]
|
|
||||||
else:
|
|
||||||
return character.global_position
|
|
||||||
|
|
||||||
func search_on_lost_target():
|
|
||||||
if !character.is_player_visible():
|
|
||||||
Transitioned.emit(self, "attack")
|
|
||||||
|
|
||||||
func move_target_adj(position):
|
|
||||||
return Vector3(position.x, character.global_position.y, position.z)
|
|
||||||
|
|
||||||
func rotate_to_face2D(object, target, target_offset_angle, delta, turn_speed):
|
|
||||||
#to allow both nodes and positions to be passed to this function, test the target and use Vector3 coords
|
|
||||||
var target_transformed
|
|
||||||
if target == null:
|
|
||||||
target_transformed = object.global_position
|
|
||||||
elif target is Vector3:
|
|
||||||
target_transformed = target
|
|
||||||
elif target is Node3D:
|
|
||||||
target_transformed = target.global_position
|
|
||||||
|
|
||||||
var pos2d = Vector2(object.global_position.x, object.global_position.z)
|
|
||||||
var target_pos2d = Vector2(target_transformed.x, target_transformed.z)
|
|
||||||
var direction = (pos2d - target_pos2d)
|
|
||||||
return lerp_angle(object.global_rotation.y, atan2(direction.x, direction.y) + deg_to_rad(target_offset_angle), delta * turn_speed)
|
|
||||||
|
|
||||||
func rotate_to_face3D(object: Node3D, target, target_offset_angle: Vector3, delta: float, turn_speed: float):
|
|
||||||
if target == null:
|
|
||||||
return
|
|
||||||
|
|
||||||
var target_positon
|
|
||||||
|
|
||||||
if target is Vector3:
|
|
||||||
target_positon = target
|
|
||||||
else:
|
|
||||||
target_positon = target.global_position
|
|
||||||
|
|
||||||
var desired_rotation = object.global_transform.looking_at(target_positon, Vector3.UP).basis.get_euler()
|
|
||||||
var current_rotation = object.global_rotation
|
|
||||||
|
|
||||||
#Interpolate each axis
|
|
||||||
current_rotation.x = lerp_angle(current_rotation.x, desired_rotation.x + target_offset_angle.x, delta * turn_speed)
|
|
||||||
current_rotation.y = lerp_angle(current_rotation.y, desired_rotation.y + target_offset_angle.y, delta * turn_speed)
|
|
||||||
current_rotation.z = lerp_angle(current_rotation.z, desired_rotation.z + target_offset_angle.z, delta * turn_speed)
|
|
||||||
|
|
||||||
#clamp pitch
|
|
||||||
var max_downward_pitch = deg_to_rad(85)
|
|
||||||
var min_upward_pitch = deg_to_rad(-45)
|
|
||||||
current_rotation.x = clamp(current_rotation.x, min_upward_pitch, max_downward_pitch)
|
|
||||||
|
|
||||||
object.global_rotation = current_rotation
|
|
||||||
|
|
||||||
func move_to_nav_point(delta):
|
|
||||||
var destination = character.nav_agent.get_next_path_position()
|
|
||||||
var local_destination = destination - character.global_position
|
|
||||||
var new_velocity = local_destination.normalized() * move_speed
|
|
||||||
|
|
||||||
character.nav_agent.set_velocity(new_velocity)
|
|
||||||
character.global_rotation.y = rotate_to_face2D(character, destination, 0, delta, body_turn_speed)
|
|
||||||
|
|
||||||
func velocity_computed(safe_velocity):
|
|
||||||
character.velocity = character.velocity.move_toward(safe_velocity, .25)
|
|
||||||
|
|
||||||
func update_minimap(priority, duration, color):
|
|
||||||
SignalBus.emit_signal("ui_minimap_point", character, character.global_position, 1, duration, color)
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
extends Node
|
extends Node
|
||||||
class_name StateMachine
|
class_name StateMachine
|
||||||
|
|
||||||
@export var player : Player
|
@export var player_character : Player
|
||||||
@export var initial_state : State
|
@export var initial_state : State
|
||||||
|
|
||||||
var current_state : State
|
var current_state : State
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ var last_ground_pos
|
|||||||
@export var BASE_FOV : float = 80
|
@export var BASE_FOV : float = 80
|
||||||
@export var FOV_CHANGE = 1.5
|
@export var FOV_CHANGE = 1.5
|
||||||
|
|
||||||
|
## Movement
|
||||||
|
var input_dir
|
||||||
|
|
||||||
## GUNS AND AMMO
|
## GUNS AND AMMO
|
||||||
var gun : Node
|
var gun : Node
|
||||||
var holstered_gun_id : int
|
var holstered_gun_id : int
|
||||||
@@ -174,103 +177,6 @@ func _input(event) -> void:
|
|||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
|
|
||||||
if !dead and !level_control.paused:
|
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
|
# Head bob
|
||||||
t_bob += delta * velocity.length() * float(is_on_floor())
|
t_bob += delta * velocity.length() * float(is_on_floor())
|
||||||
camera.transform.origin = _headbob(t_bob)
|
camera.transform.origin = _headbob(t_bob)
|
||||||
@@ -333,11 +239,6 @@ func _physics_process(delta):
|
|||||||
if level_control.gamemode.stamina_regen == true:
|
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)
|
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():
|
if Input.is_action_pressed("inspect") and !gun.anim_player.is_playing():
|
||||||
gun.anim_player.play("inspect")
|
gun.anim_player.play("inspect")
|
||||||
|
|
||||||
@@ -349,12 +250,6 @@ func _physics_process(delta):
|
|||||||
flashlight_on = true
|
flashlight_on = true
|
||||||
flashlight_audio.play()
|
flashlight_audio.play()
|
||||||
|
|
||||||
|
|
||||||
# Shooting & fire modes
|
|
||||||
if Input.is_action_pressed("shoot"):
|
|
||||||
if gun != null:
|
|
||||||
gun.shoot()
|
|
||||||
|
|
||||||
# Gun folding out of the way
|
# Gun folding out of the way
|
||||||
if gun_ray.is_colliding():
|
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))
|
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)
|
hold_item(delta)
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
crouch(delta)
|
crouch(delta)
|
||||||
weapon_tilt(input_dir.x, delta)
|
weapon_tilt(input_dir, delta)
|
||||||
weapon_sway(delta)
|
weapon_sway(delta)
|
||||||
weapon_bob(velocity.length(), delta)
|
weapon_bob(velocity.length(), delta)
|
||||||
|
|
||||||
## MOVEMENT
|
## 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():
|
func joypad_walk():
|
||||||
# Joypad right stick look control
|
# Joypad right stick look control
|
||||||
var dir_out = Vector2(0,0)
|
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_far_enabled = false
|
||||||
camera.attributes.dof_blur_near_enabled = false
|
camera.attributes.dof_blur_near_enabled = false
|
||||||
|
|
||||||
func weapon_tilt(input_x, delta):
|
func weapon_tilt(input, delta):
|
||||||
if !ads:
|
if input:
|
||||||
if weapon_holder:
|
if !ads:
|
||||||
weapon_holder.rotation.z = lerp(weapon_holder.rotation.z, -input_x * weapon_rotation_amount * 10, 4 * delta)
|
if weapon_holder:
|
||||||
if camera:
|
weapon_holder.rotation.z = lerp(weapon_holder.rotation.z, -input.x * weapon_rotation_amount * 10, 4 * delta)
|
||||||
camera.rotation.z = lerp(camera.rotation.z, -input_x * HEAD_TILT_AMT, 5 * delta)
|
if camera:
|
||||||
|
camera.rotation.z = lerp(camera.rotation.z, -input.x * HEAD_TILT_AMT, 5 * delta)
|
||||||
|
|
||||||
func weapon_sway(delta):
|
func weapon_sway(delta):
|
||||||
#aim gun at center screen
|
#aim gun at center screen
|
||||||
|
|||||||
@@ -66,6 +66,12 @@ func _ready():
|
|||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(_delta):
|
func _process(_delta):
|
||||||
|
if Input.is_action_pressed("shoot"):
|
||||||
|
shoot()
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("reload"):
|
||||||
|
reload()
|
||||||
|
|
||||||
if chamber != null:
|
if chamber != null:
|
||||||
var rot_amount = revolver_chamber_rot_amt * _delta * 10
|
var rot_amount = revolver_chamber_rot_amt * _delta * 10
|
||||||
chamber.rotate_object_local(Vector3(0,-1,0),deg_to_rad(rot_amount))
|
chamber.rotate_object_local(Vector3(0,-1,0),deg_to_rad(rot_amount))
|
||||||
|
|||||||
Reference in New Issue
Block a user