diff --git a/assets/player.tscn b/assets/player.tscn index 4a2ab7e..4743db3 100644 --- a/assets/player.tscn +++ b/assets/player.tscn @@ -313,6 +313,9 @@ libraries = { "": SubResource("AnimationLibrary_d0x8a") } +[node name="velocity_ray" type="RayCast3D" parent="."] +transform = Transform3D(1, -2.21121e-11, 5.69206e-32, 2.21121e-11, 1, 0, -5.69206e-32, 1.25837e-42, 1, 0.000168126, -1.01843, -0.00105944) + [connection signal="tree_entered" from="." to="." method="_on_tree_entered"] [connection signal="body_entered" from="pick_up_detection" to="." method="_on_pick_up_detection_body_entered"] [connection signal="body_entered" from="pick_up_magnet" to="." method="_on_pick_up_magnet_body_entered"] diff --git a/scripts/player.gd b/scripts/player.gd index f9b564c..e6355a4 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -2,7 +2,9 @@ extends CharacterBody3D const JUMP_VELOCITY = 5 const JUMP_WEAPON_DIP = Vector3(0,-5,0) -const WALK_TRANSITION_SPEED = 7 +const AIR_TRANSITION_SPEED = 7 +const GROUND_TRANSITION_SPEED = 4 + const MAX_AIR_DASH = 1 const FLASHLIGHT_BRIGHTNESS = 30 const KICK_AMOUNT = 20 @@ -30,6 +32,7 @@ const L_JOYSTICK_DEADZONE = .2 const L_JOYSTICK_SENSITIVITY = .1 var speed +var walk_transition_speed var double_jump = true var air_dash = MAX_AIR_DASH var gravity = 9.8 @@ -70,6 +73,7 @@ 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 hitmarker = load("res://hitmarker.tscn") var instance_bullet var instance_casing @@ -216,13 +220,16 @@ func _physics_process(delta): # Handle jump. - if Input.is_action_just_pressed("jump") and is_on_floor() and !is_climbing: - velocity.y += JUMP_VELOCITY - weapon_dip_pos += JUMP_WEAPON_DIP - crouched = false - elif Input.is_action_just_pressed("jump") and double_jump == true and !is_climbing: - velocity.y += JUMP_VELOCITY - double_jump = false + if Input.is_action_just_pressed("jump"): + if is_on_floor() and !is_climbing: + velocity.y += JUMP_VELOCITY + weapon_dip_pos += JUMP_WEAPON_DIP + crouched = false + elif wall_jump(): + velocity += 2 * Vector3(-velocity.x,10,-velocity.z) + elif double_jump == true and !is_climbing: + velocity.y += JUMP_VELOCITY + double_jump = false ## HANDLE MOVEMENT DIRECTION var input_dir @@ -263,9 +270,10 @@ func _physics_process(delta): #walking if is_on_floor() and !is_climbing: + walk_transition_speed = AIR_TRANSITION_SPEED if direction: - velocity.x = lerp(velocity.x, direction.x * speed, delta * WALK_TRANSITION_SPEED) - velocity.z = lerp(velocity.z, direction.z * speed, delta * WALK_TRANSITION_SPEED) + velocity.x = lerp(velocity.x, direction.x * speed, delta * walk_transition_speed) + velocity.z = lerp(velocity.z, direction.z * speed, delta * walk_transition_speed) else: velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5) + (direction.x * DASH_SPEED) velocity.z = lerp(velocity.z, direction.z * speed, delta * 6.5) + (direction.z * DASH_SPEED) @@ -551,6 +559,15 @@ func ladder_collide(): else: 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 + else: + return false + ## VARIOUS ACTIONS func flashlight_toggle(): if flashlight_on: