add pressure plate
This commit is contained in:
parent
3a66839841
commit
9432084b53
9 changed files with 275 additions and 26 deletions
35
gmtk_2024/scripts/PressurePlate.gd
Normal file
35
gmtk_2024/scripts/PressurePlate.gd
Normal file
|
@ -0,0 +1,35 @@
|
|||
extends StaticBody2D
|
||||
|
||||
@export var laser_path: NodePath # TODO
|
||||
@export var required_scale: Vector2 = Vector2(1.0, 1.0)
|
||||
@export var player_required_scale: Vector2 = Vector2(2.0, 2.0)
|
||||
|
||||
@onready var animation = $AnimationPlayer
|
||||
|
||||
var laser: Node2D = null
|
||||
var is_activated = false
|
||||
|
||||
func _ready():
|
||||
laser = get_node(laser_path)
|
||||
|
||||
func _on_body_entered(body: Node):
|
||||
print("Wird erkannt")
|
||||
if (body is StaticBody2D and body.scale >= required_scale) or (body is CharacterBody2D and body.scale >= player_required_scale):
|
||||
animation.play("Disable")
|
||||
activate_plate()
|
||||
|
||||
func _on_body_exited(body: Node):
|
||||
if (body is StaticBody2D and body.scale >= required_scale) or (body is CharacterBody2D and body.scale >= player_required_scale):
|
||||
animation.play("Enable")
|
||||
deactivate_plate()
|
||||
|
||||
func activate_plate():
|
||||
print("wird aktiviert")
|
||||
if not is_activated:
|
||||
is_activated = true
|
||||
if laser:
|
||||
laser.queue_free()
|
||||
|
||||
func deactivate_plate():
|
||||
if is_activated:
|
||||
is_activated = false
|
Loading…
Add table
Add a link
Reference in a new issue