I feel like this should be really simple but I just cant seem to get it to work.
I’m making a pinball game and trying to make a rail system that has different collision, so I used one node for an entrance, one for an exit, and one for the physics based, rigid body 2d, ball.
here is the code I got
rail_entrence
extends Node2D
signal rail_enter
signal trans
func _on_rail_enter():
emit_signal("trans")
print("rail entered")
func _on_area_2d_body_entered(body: Node2D) -> void:
emit_signal("rail_enter")
print("body entered")
rail_exit
extends Node2D
signal rail_exit
signal trans
func _on_rail_exit():
emit_signal("trans")
print("rail exit")
func _on_area_2d_body_entered(body: Node2D) -> void:
emit_signal("rail_exit")
print("body exit")
Ball
extends Node2D
func _on_Rail_exit_rail_exit() -> void:
$Ball2.set_collision_layer_value(1,true)
$Ball2.set_collision_layer_value(3,false)
$Ball2.set_collision_mask_value(1,true)
$Ball2.set_collision_mask_value(3,false)
func _on_Rail_exit_trans() -> void:
$Ball2.set_deferred("freeze", true)
await get_tree().create_timer(1.0).timeout
$Ball2.set_deferred("freeze", false)
func _on_Rail_entrence_trans() -> void:
$Ball2.set_deferred("freeze", true)
await get_tree().create_timer(1.0).timeout
$Ball2.set_deferred("freeze", false)
func _on_Rail_entrence_rail_enter() -> void:
print("Rail entered: received")
$Ball2.set_collision_layer_value(1,false)
$Ball2.set_collision_layer_value(3,true)
$Ball2.set_collision_mask_value(1,false)
$Ball2.set_collision_mask_value(3,true)
The Idea is that I have a separate collision shapes on layer 3 and the game would take a second, change collision layers, and then continue down the path, then hit the exit and change collision layers back but the “Rail entered: received” never shows. I’ve tried many different things and I want to see what im doing wrong with signals.
Note:
I have the rail_entrence and the rail_exit in the main game scene so I should be able to receive the signal from the rail test node that is the rail_entrence, the rail_exit, and the 3rd layer frozen rigidbody2d collision.
IDK but any help would be greatly appreciated.






