Godot Version
4.2.1
Question
I am working on a binding of isaac-like game. The rooms are transitioned between using a ladder of signals going from a Door → Wall → Room → DungeonFloor → GameScript as shown below:
Door:
func _on_body_entered(body) → void:
if body is Player:
print(“Door signal”)
body = body as Player
emit_signal(“door_entered”,body,self)
Wall:
func on_door_entered(player:Player,entered_door:Door) → void:
print(“Wall signal”)
emit_signal(“door_entered”,player,entered_door,wall_direction)
Room:
func on_door_entered(player:Player,door:Door,direction:Vector2i) → void:
emit_signal(“door_entered”,player,door,direction,coords)
DungeonFloor:
This function will be called by a child room when a door is entered.
On the door being entered, the dungeon floor needs to figure out where to send the player
And relay this information back to the game engine.
func on_door_entered(player:Player,door:Door,entry_direction:Vector2i,room_coord:Vector2i):
print(“Dungeon signal”)
assert(dungeon.has(entry_direction+room_coord),
“Tried to move into a room that doesnt exist. Check doors.”)
assert(entry_direction.length() == 1,“Direction is not a unit vector.”)
match entry_direction:
Vector2i.UP:
assign_new_room(next_room_up)
Vector2i.DOWN:
assign_new_room(next_room_down)
Vector2i.LEFT:
assign_new_room(next_room_left)
Vector2i.RIGHT:
assign_new_room(next_room_right)
emit_signal(“door_entered”,player,current_room,-entry_direction)
This function will add the current room into the
func assign_new_room(new_room) → void:
add_child(new_room)
if current_room != null:
call_deferred(“remove_child”,current_room)
current_room = new_room
current_room_coords = new_room.coords
assign_adjacent_rooms(new_room)
func assign_adjacent_rooms(room:Room) → void:
next_room_down = null
next_room_left = null
next_room_right = null
next_room_up = null
if room.has_bottom_door:
next_room_down = dungeon.get(room.coords + Vector2i.DOWN)
if room.has_left_door:
next_room_left = dungeon.get(room.coords + Vector2i.LEFT)
if room.has_right_door:
next_room_right = dungeon.get(room.coords + Vector2i.RIGHT)
if room.has_top_door:
next_room_up = dungeon.get(room.coords + Vector2i.UP)
GameScript:
This function will be called upon a room being entered by the dungeon floor
This function will be responsible for moving the player to that new room as well as updating the
minimap.
func on_door_entered(player:Player,new_room:Room,exit_direction:Vector2i) → void:
assert(exit_direction.length() == 1,“Exit direction vector passed is not a unit vector.”)
#TODO fix this. It works, but is extremely error-prone.
player.global_position = new_room.get_wall_in_direction(exit_direction).get_node(“door”).global_position - (exit_direction as Vector2 * 30)
in_game_ui.minimap.update_map(new_room)
print(“Game State reached”)
I also have a minimap that displays what room the player is in:
When the player tries to go through a door that has at least two rooms in that direction, they consistently end up in the second room. They do enter the first room for a brief moment but then skip right to the next one.
For example, when I tried to go to the room to the right, I entered the room before the C-room for a brief moment before ending up in the C-room.
Any thoughts on how to solve this would be greatly appreciated