#Simple Scene transition when player enters Area2d

21 messages · Page 1 of 1 (latest)

karmic pendant
#

I have an Area2d with a CollisionShape on the right edge of my screen and I want to switch to another scene when my character enters the shape - but right now the player just leaves the screen forever.

I've got them both in the same Z Index but how to I get this to transition (I'm making a basic adventure game) to this other scene?

The script on my Area2d looks like this

extends Area2D

#Called when the Area2D enters another area
func _on_Area2D_body_entered(body: Node) -> void:
if body is CharacterBody2D:
# Load a new scene when the player character enters the trigger zone
load_new_scene()

func load_new_scene() -> void:
# Replace "res://Scenes/room1.tscn" with the actual path to your new scene
var new_scene = preload("res://Scenes/room1.tscn")
get_tree().change_scene(new_scene)

left magnet
#

what node is the player?

#

and is the path to the new scene correct? cause it looks like it's a placeholder

karmic pendant
#

The player is a CharacterBody2D and yes, that's the actual path - I just accidentally changed it in both places

#

I feel like I need some script on the player as well

left magnet
#

if you have a print in _on_Area2D_body_entered, does it fire?

karmic pendant
#

I’ll test that tomorrow, thanks for the tip

karmic pendant
#

Hey again, I am not seeing the print fire-ing but I do have a couple errors I am not sure about

karmic pendant
#

SOLVED THANKS!

left magnet
#

what was it?

karmic pendant
#

I didn't connect the function inside of the Area2d

#

Connections are really confusing for me

#

I needed to connect the "body_entered" signal to the transition area2d

#

I was connecting it to the character mistakenly

#

But now I am having a weird problem where the collision objects from one scene are playing out in another scene when i do "run project" but not when i do "run current scene'

left magnet
#

check Project Settings > General > Application > run. is the main scene the one you are starting from. and if not, what is happening between the main scene and current scene?

karmic pendant
#

I think I figured it out. I thought I needed to have a main scene

#

with all the scenes "in it"

#

And so running the "main" scene was running all the scenes at once