Pressure Plate Activation

Hello!

I’m not sure if this is just a me issue, but when two players were both standing on the same plate it would trigger the bridge activation.

I solved this by adding an @export var for the area_collision: Area2D and checking the overlapping_bodies().size in both the _on_area_2d_body_entered(_body) func, and the _on_area_2d_body_exited(_body) func and making sure it doesn’t doubly add a body count on the same pressure plate:

@export var area_collision: Area2D

func _on_area_2d_body_entered(_body):
	if multiplayer.multiplayer_peer == null:
		return
	if not multiplayer.is_server():
		return

	#print("area_collision.get_overlapping_bodies().size() entered: " + str(area_collision.get_overlapping_bodies().size()))

	if area_collision.get_overlapping_bodies().size() > 1:
		return

	bodies_on_plate += 1
	update_plate_state()

func _on_area_2d_body_exited(_body):
	if multiplayer.multiplayer_peer == null:
		return
	if not multiplayer.is_server():
		return
	
	#print("area_collision.get_overlapping_bodies().size() exited: " + str(area_collision.get_overlapping_bodies().size()))
	
	if area_collision.get_overlapping_bodies().size() > 0:
		return
	
	bodies_on_plate -= 1
	print(bodies_on_plate)
	update_plate_state()

There’s probably an easier way to do this, but this is how I did it if it helps anyone else!

Wow, great catch!

I did come up with a slightly simpler version to fix the bug:

func update_plate_state():
	var was_down = is_down
	is_down = bodies_on_plate >= 1
	if is_down != was_down:
		toggle.emit(is_down)
	set_plate_properties()

Basically, the toggle signal should only emit if the is_down property actually changed.

2 Likes

Ooo, nice one, thanks!

Hey great catch and thanks for sharing your solution!

Privacy & Terms