compsci_godot_albert/_subsections/sec05/lesson-07.org
2025-07-29 01:31:46 +03:00

50 lines
1.6 KiB
Org Mode

#+title: Section 05 - Lesson 07 | Plane Jump Movement
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../../_share/media/css/godot.css" />
#+OPTIONS: H:6
* Links
- [[../../toc.org][TOC - Godot Notes]]
- [[https://www.udemy.com/course/jumpstart-to-2d-game-development-godot-4-for-beginners/learn/lecture/49010965#overview][S05:L07 - video]]
* 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
#+attr_html: :width 600px
file:../../_share/media/img/albert/section-05/lesson-07/ex01.png
- add event to action
- hit the + to the right of the action name
#+attr_html: :width 600px
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
#+begin_src gdscript
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()
#+end_src