added wall running and jumping

This commit is contained in:
Derek
2025-02-18 22:58:01 -06:00
parent be729ac78f
commit 1d75036a31
7 changed files with 251 additions and 35 deletions

View File

@@ -73,7 +73,9 @@ var gun_is_holstered = false
@onready var level_control = get_tree().current_scene
@onready var interact_ray = $Head/Recoil/Camera3D/InteractRay
@onready var bullet_ray = $Head/Recoil/Camera3D/BulletRay
@onready var velocity_ray: RayCast3D = $velocity_ray
@onready var wall_ray_1: RayCast3D = $wall_ray1
@onready var wall_ray_2: RayCast3D = $wall_ray2
@onready var wall_ray_3: RayCast3D = $wall_ray3
@onready var hitmarker = load("res://hitmarker.tscn")
var instance_bullet
var instance_casing
@@ -112,6 +114,10 @@ var held_key_check = 0.0
# Slow Down Variables
var remaining_stamina : float = MAX_STAMINA
# Wall Jump
var can_wall_jump = true
# Pickups
var picked_up = false
var picked_up_text
@@ -156,6 +162,7 @@ var controlled_elsewhere = false
@onready var hud: Control = $Head/Recoil/Camera3D/HUD
@onready var clock_sound: AudioStreamPlayer = $Audio/ClockSound
@onready var weapon_select_menu: Control = $Head/Recoil/Camera3D/WeaponSelect
@onready var wall_jump_timer: Timer = $WallJumpTimer
func _ready():
@@ -208,7 +215,6 @@ func _physics_process(delta):
if !dead and !level_control.paused:
# Add the gravity.
if is_on_floor():
double_jump = true
@@ -226,7 +232,7 @@ func _physics_process(delta):
weapon_dip_pos += JUMP_WEAPON_DIP
crouched = false
elif wall_jump():
velocity += 2 * Vector3(-velocity.x,10,-velocity.z)
velocity += Vector3(velocity.x * 5,10,velocity.z * 5)
elif double_jump == true and !is_climbing:
velocity.y += JUMP_VELOCITY
double_jump = false
@@ -249,7 +255,17 @@ func _physics_process(delta):
velocity.x += direction.x * DASH_SPEED
velocity.z += direction.z * 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():
@@ -290,6 +306,12 @@ func _physics_process(delta):
else:
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5)
velocity.z = lerp(velocity.z, direction.z * speed, delta * 6.5)
## wall_run
if wall_ray_1.is_colliding() or wall_ray_2.is_colliding():
if abs(Vector2(velocity.x,velocity.y)) >= Vector2(5.0,5.0):
velocity.y = clamp(velocity.y,-2,abs(velocity.y))
#velocity.x += -velocity.x * .01 * delta
#velocity.z += -velocity.z * .01 * delta
# Head bob
t_bob += delta * velocity.length() * float(is_on_floor())
@@ -560,14 +582,20 @@ func ladder_collide():
gravity = default_gravity
func wall_jump():
velocity_ray.rotation = velocity.normalized()
print("VELOCITY NORMALIZED: ",velocity.normalized())
print("VELOCITY RAY ROTATION: ", velocity_ray.rotation)
if velocity_ray.is_colliding():
return true
print("CAN JUMP? ",can_wall_jump)
if can_wall_jump == true:
if wall_ray_1.is_colliding() or wall_ray_2.is_colliding() or wall_ray_3.is_colliding():
can_wall_jump = false
wall_jump_timer.start()
return true
else:
return false
else:
return false
func _on_wall_jump_timer_timeout() -> void:
can_wall_jump = true
## VARIOUS ACTIONS
func flashlight_toggle():
if flashlight_on: