compsci_godot_albert/_subsections/sec04/lesson-08.org
2025-03-10 03:33:49 +02:00

1.5 KiB

#+title:Flyin#+title: Section 04 - Lesson 08 | Collisions: Hitting the floor

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
# 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 properller animation

  • switch to plane scene
  • Cmd + drag AnimationSprite to script
  • in die set the variable to the sprite to 'stop()'
func die() -> void:
	set_physics_process(false)
	animated_spirte_2d.stop()