I need help with traps

Godot Version 4.2.1

Im trying to make a pixel art animated trap using a CharacterBody2d node, An AnimatedSprite2d node, a CollisionShape2d node, and some timers.

The idea is to have a jet of flame shoot up at a set time. The player has to use the time between flames to proceed.

Im using the flame trap spriteset by Foozle (Pixel Trap Pack - 30 Animated Traps by FoozleCC), and i’ve split it into two sections in the animated sprite node (flame and idle).

I have 3 timers, one set at 4 seconds, one set at 8 seconds, and one set at 10 seconds. Ill drop my script down below.


extends CharacterBody2D
@onready var timer = $Timer
@onready var flame = $CollisionShape2D
@onready var idle_animation : AnimatedSprite2D = $AnimatedSprite2D
var animation_finished = false
var idle = true
var loop : bool = true
var speedbump : bool = false
@onready var timer_2 = $Timer2
@onready var timer_3 = $Timer3

func start():
if idle == true:
$CollisionShape2D.shape.extents = Vector2 (0,0)
idle_animation.play(“idle”)
_on_timer_timeout()
func _on_timer_timeout():
if idle == true:
idle = false
next()
func next():
if idle == false:
$CollisionShape2D.shape.extents = Vector2 (9,58.125)
idle_animation.play(“flame”)
_on_timer_2_timeout()
func _on_timer_2_timeout():
if idle == false:
idle = true
if speedbump == true:
start()

func _on_timer_3_timeout():
speedbump = true


I’ve looked it up, and i cant find anything in how to make traps of this kind.
If someone here can help me that would be great!

Thanks!

I think you are going about this the wrong way. You should leverage the animation player to sequence everything, instead of using timers.

Animation players can call functions. So what I would do is create another animation player that does the sequence.

Start
Idle
Flame
Loop

Keep some state going that can trigger the speed bump action and change the loop animation.

If we leave your code as is here are some suggestions…

Because you call the signal function on each timer you won’t get the effect your looking for.

Don’t call the _on_timers directly.

Your start function should trigger all the timers as one-shot. And the last longest timer will call start to set it up again.

I’ll try it. Thanks!!!