Not colliding with fire trap

Godot Version

version 4.2.1

Question

The fire trap doesn’t activate when the player collides with it, but it activates when the player stands on it for a few seconds. What am I doing wrong?

here’s the video:

here’s the code for collision, main.gd:

extends Node2D

func _physics_process(delta):
	Saw()
	for i in $Player.get_slide_collision_count():
		var collision = $Player.get_slide_collision(i)
		collision = collision.get_collider()
		print("Collided with: %s" % collision.name)
		
		if collision.name == "Trampoline":
			Trampoline()
		elif collision.name.begins_with("Spikes"):
			Spikes()
			$MetalHitSound.play()
		elif collision.name.begins_with("Saw"):
			$Player.die()
			$MetalHitSound.play()
		elif collision.name.begins_with("Fire"):
			var Fire = collision
			Fire.FireHit = true
			if Fire.FireHit == true and Fire.FireOn == true:
				$Player.die()
		elif collision.name.begins_with("Box"):
			var Box = collision
			Box.BoxHit = true
			$Player.velocity.y = -700

here’s the code for fire trap, fire.gd:

extends AnimatableBody2D

var FireHit = false
var FireOn = false
func _process(delta):
	if FireHit == true and FireOn == false:
		$AnimatedSprite2D.play("hit")
	if $AnimatedSprite2D.frame == 3:
		FireOn = true
		FireHit = false
		$AnimatedSprite2D.play("on")
		$Timer.start(5)

func _on_timer_timeout():
	$AnimatedSprite2D.play("off")
	FireOn = false

here’s the screenshot of my editor:

The video link you provided doesn’t work! (prompts me to login)

Looking at the code of your fire trap, it shouldn’t do anything by default (because both FireHit and FireOn are false). Assuming your main.gd script sets FireHit to true, it will start playing the “hit” animation every frame. I don’t see why it would ever reach the third frame that way, so my best guess would be that you reset FireHit back to False somewhere?

The video will display after you log in to Google Drive. If it still doesn’t show the video, please let me know.

The FireHit variable resets back to False in fire.gd after the 3rd frame because I want to stop the animation on the 3rd frame. Should I reset FireHit to False in main.gd instead?

The collision and animation work normally when the player stands on the fire trap, but they do not work when the player runs through the trap.

try fire_hit = false after the 5 second timer

Edith: oh, so it doesn’t work because of $AnimatedSprite because then 2 animations are running. I think the player is running too fast and that’s why the 3rd frame isn’t reached. I can’t watch the video because I’m getting an error message from Google.

Edith I hope I’m not confusing you: Is it even possible in main.gd for fireHit and fireOn to be true at the same time?

No. I am logged in. It wants me to “request access”.

Judging by the code you shared, this is what should happen:

  • The fire nodes are initialized, both FireHit and FireOn are false, so the “hit” animation won’t be played. Assuming you’re using a default animation with at least three frames, all fire nodes will reach the third frame eventually and toggle FireOn to true, before starting the “on” animation and a 5 seconds timer.
  • If the player now collides with a fire node, they should die (since FireOn is true already and your main.gd code sets FireHit to true as well).
  • If they don’t however, the “on” animation might reach its third frame (assuming it has this many) which will reset the “on” animation to frame 1 and start yet another timer. If so, this process will repeat every 3 frames!

The latter is probably not what you want. That being said, I don’t see how any of this would explain why the player has to stand multiple seconds on a fire trap for it to kill them. There’s nothing in your code that would explain this behavior.