Browse Source

:tada: Implement jump ability

DricomDragon 1 year ago
parent
commit
32b00ce581
1 changed files with 6 additions and 1 deletions
  1. 6 1
      first3d/component/entity/walker/walker.gd

+ 6 - 1
first3d/component/entity/walker/walker.gd

@@ -5,6 +5,8 @@ extends CharacterBody3D
 @export var speed = 14
 # The downward acceleration when in the air, in meters per second squared.
 @export var fall_acceleration = 75
+# Vertical impulse applied to the character upon jumping in meters per second.
+@export var jump_impulse = 20
 
 var target_velocity = Vector3.ZERO
 
@@ -19,7 +21,10 @@ func _physics_process(delta: float) -> void:
 	target_velocity.z = ground_velocity.y * speed
 
 	# Vertical Velocity
-	if not is_on_floor(): # If in the air, fall towards the floor. Literally gravity
+	if is_on_floor():
+		if Input.is_action_just_pressed("jump"):
+			target_velocity.y = jump_impulse
+	else:
 		target_velocity.y = target_velocity.y - (fall_acceleration * delta)
 
 	# Moving the Character