Hello all! I am attempting to make my first game, which is a top-down 2D RPG in the style of Dragon Warrior/Dragon Quest. I have a basic overworld composed of a Node2D with a TileMapLayer which provides the terrain and impassible obstacles (mountains, water, etc). I have a Player scene composed of a CharacterBody2D with animations and a CollisionShape2D which I have moving around the map in a satisfactory manner. So far so good. Next I want to add different regions to the map which, upon entry, will update some settings about the frequency of random encounters and a dictionary containing which encounters are possible (along with their relative rarity).
In order to accomplish this, I created a scene called DifficultyRegion which extends Area2D. My thought process is that I could create multiple DifficultyRegion nodes in the overworld, give them each a child CollisionShape2D in the overworld (so the overworld scene controls the placement of each zone), and then use the GDScript of the DifficultyRegion to emit a signal whenever the player enters that region. My script is as follows:
class_name DifficultyRegion
extends Area2D
@export
var region_name: String
@export
var encounter_frequency: int
@export
var encounter_types: Dictionary
signal difficulty_region_changed(region_name: String, encounter_frequency: int, encounter_types: Dictionary)
func _on_body_entered(body: Node2D) -> void:
print("DifficultyRegion Entered by body of type " + body.get_class())
if body.get_class() == "Player":
difficulty_region_changed.emit(region_name, encounter_frequency, encounter_types)
Unfortunately, in spite of hooking up the signal 'body_entered' signal of the Area2D to the to the _on_body_entered() function, it doesn't seem to be firing at all. Can anyone spot what I'm doing wrong?