57 lines
1.5 KiB
Org Mode
57 lines
1.5 KiB
Org Mode
#+title:Flyin#+title: Section 04 - Lesson 08 | Collisions: Hitting the floor
|
|
#+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/45069817#overview][S04:L53.08 - video]]
|
|
|
|
* Notes
|
|
|
|
** when a character body2d hits the floor
|
|
- velocity is set to 0
|
|
- is_on_floor is set to true
|
|
|
|
** create a floor
|
|
to create a floor we are going to use a StaticBody2D
|
|
|
|
|
|
1. make this as a seperate scene
|
|
2. add root node StaticBody2D
|
|
3. add CollisionShape2D as child
|
|
4. in collisionshape2D inspector go to shape and pick rectangle shape
|
|
5. stretch the rectangle across the scene
|
|
6. save scene
|
|
|
|
** add barrier to game
|
|
1. add the barrier scene to the game scene
|
|
2. put it at top of screen or whereever you like
|
|
3. Ctrl+D to create another one and move it to the floor
|
|
|
|
** when plane hits floor stop it from moving
|
|
- in physics process func check if 'in on floor'
|
|
- if so than invoke die
|
|
|
|
#+BEGIN_SRC gdscript
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
# ...
|
|
|
|
if is_on_floor() == true:
|
|
die()
|
|
|
|
func die() -> void:
|
|
set_physics_process(false)
|
|
#+end_src
|
|
|
|
** end properller animation
|
|
- switch to plane scene
|
|
- Cmd + drag AnimationSprite to script
|
|
- in die set the variable to the sprite to 'stop()'
|
|
|
|
#+BEGIN_SRC gdscript
|
|
func die() -> void:
|
|
set_physics_process(false)
|
|
animated_spirte_2d.stop()
|
|
#+end_src
|