ladder working
This commit is contained in:
@@ -4,6 +4,8 @@ extends CharacterBody3D
|
||||
var speed
|
||||
var double_jump = true
|
||||
var gravity = 9.8
|
||||
var is_climbing = false
|
||||
var ladder_center
|
||||
var default_gravity = gravity
|
||||
var mouse_input : Vector2
|
||||
|
||||
@@ -101,9 +103,9 @@ func _physics_process(delta):
|
||||
double_jump = true
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor() and !is_climbing:
|
||||
velocity.y += JUMP_VELOCITY
|
||||
elif Input.is_action_just_pressed("jump") and double_jump == true:
|
||||
elif Input.is_action_just_pressed("jump") and double_jump == true and !is_climbing:
|
||||
velocity.y += JUMP_VELOCITY
|
||||
double_jump = false
|
||||
|
||||
@@ -116,13 +118,21 @@ func _physics_process(delta):
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
var input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
var direction = (self.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
if is_on_floor():
|
||||
if is_on_floor() and !is_climbing:
|
||||
if direction:
|
||||
velocity.x = direction.x * speed
|
||||
velocity.z = direction.z * speed
|
||||
else:
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * 6.5)
|
||||
elif is_climbing:
|
||||
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.z = lerp(velocity.z, direction.z * speed, delta * 6.5)
|
||||
else:
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * 6.5)
|
||||
@@ -278,11 +288,9 @@ func _on_pick_up_detection_body_entered(body):
|
||||
level_control.gun_spawn(weapon_id)
|
||||
|
||||
|
||||
func lader_collide(is_climbing):
|
||||
func ladder_collide(is_climbing):
|
||||
|
||||
if is_climbing == true:
|
||||
if Input.is_action_pressed("move_up"):
|
||||
velocity.y += 5
|
||||
gravity = 0.0
|
||||
else:
|
||||
gravity = default_gravity
|
||||
@@ -315,6 +323,7 @@ func weapon_recoil(delta):
|
||||
var recoil_to = camera.rotation.x + gun.recoil_amount
|
||||
camera.rotation.x = clamp(lerp(camera.rotation.x,recoil_to, .05), deg_to_rad(-90), deg_to_rad(85))
|
||||
|
||||
|
||||
func die():
|
||||
Engine.time_scale = .05
|
||||
var deadmsg = dead_announce.instantiate()
|
||||
|
||||
Reference in New Issue
Block a user