1.6 KiB
1.6 KiB
Section 05 - Lesson 07 | Plane Jump Movement
Notes
making the plane jump
- input action
- jump const / variable
- ONLY at the initial touch of jump, adjust the jump velocity
add jump
- create const variable to represent JUMP-POWER
-
add an action input
- Project->Project Settings-> Input Map
- in the "add new action" textbar enter the action name (jump)
- hit the +Add button to the right of the "add new action" field
file:../../_share/media/img/albert/section-05/lesson-07/ex01.png
-
add event to action
-
hit the + to the right of the action name
file:../../_share/media/img/albert/section-05/lesson-07/ex02.png
- an event configuration dialog pops up, you can hit the keypress or choose whatever input will activate the action
-
add code to check for the input
- in
_physics_process - check for
Input.is_action_just_pressed("name of action") -
and set
velocity.y = JUMP_POWER- physics engine will take care of the velocity changing due to gravity and distance
func _physics_process(delta: float) -> void:
velocity.y += _gravity * delta
if Input.is_action_just_pressed("jump") == true:
velocity.y = JUMP_POWER
# note we call move and slide over here to get the physics engine
# to make it's calculations
move_and_slide()