Files
foxfox/scripts/block_sensor.gd

21 lines
919 B
GDScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
extends Area2D
## Детектор направления столкновения для блоков (вопрос/кирпич).
## Реагирует, когда Fox (CharacterBody2D) касается блока, и определяет, снизу ли удар.
var block: Node = null
var triggered: bool = false
func _ready() -> void:
collision_layer = 4 # совпадает с parent layer
collision_mask = 1 # ловим Fox
body_entered.connect(_on_body_entered)
func _on_body_entered(body: Node) -> void:
if body.is_class("CharacterBody2D") and body.has_method("hit_coin"):
var fox := body as CharacterBody2D
# Fox находится ниже вершины блока => удар снизу
var block_top: float = get_global_position().y - 16.0
if fox.position.y > block_top and fox.velocity.y > 0.0:
if block != null and block.has_method("hit_from_below"):
block.hit_from_below()