How to create a triggering tile?

Hi there,
I would like to create a tile that can be triggered when the player steps on it in order to affect other desired tiles. pretty much like a pressure tile.

i've tried to make this tile an item tile, then write my code in "on collect do" but it doesn't return to normal when the player isn't on it anymore. ( or i don't know how to properly do it )

my approach:

In PLAYER script, i made a "playerUpdated" signal

on update do
	PC_X = event.px // Store starting position
	PC_Y = event.py
	
	emit "playerUpdated"
end

In ITEM script i compared the tile current position with updated player's position

on playerUpdated do
	TX = event.x
	TY = event.y
	
	
	if TX==event.px then
		if TY==event.py then
			isTriggered = "true"
		else
			isTriggered = "false"
		end
	end
end

but once I test it, it seems to have kind of a lagging issue.. especially when the player enters by the X axis.

trigger-gif

any ideas ?

thx

1 Like

I found a solution:

on collect do
	TX = event.x
	TY = event.y
	
	isTriggered =1
end

on playerUpdated do
  
	if TX != event.px then
	  isTriggered = 0
	  elseif TY != event.py then
	    isTriggered = 0
	  end
end

Can't really tell why but it works much better.

1 Like