![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | kayfleisch |
Alright. First time working in Godot. I’ve tried solving this via tutorials and docs, previous posts but nothing is working. Working on making a simple game to learn the process. It’s all in 2D.
The game: KinematicBody2D (player controls) try’s to knock a ball (KinematicBody2D, not controlled) into a goal. The goal is created by making a gap in the walls, so only a small part of the rectangular arena allows the ball to pass through, there is art to show the entrance of the goal, but the actual Area2D box representing the goal is not in the scene. I want to use a signal to connect the action of passing through the goal to initiate the next level.
What I’ve tried (and not succeeded with):
I made a Sprite with Area2D I titled Hitbox, and a CollisionShape as children of the Sprite. I placed the shapes at the line between goal and arena.
Here is my script:
extends Sprite
func on_Hitbox_body_entered(body) → void:
if body.is_in_group(“ObjectGroup”):
get_tree().change_scene("res://Level" + str(int(get_tree().current_scene.name) + 1) + “.tscn”)
I have the ball titled Object and in a group called ObjectGroup
I have all the Levels titled Level_1, Level_2,Level_3, etc (I got this idea for the level change from a youtube video)
I’ve also tried the following script
extends Sprite
func on_hitbox_area_entered(area: Area2D) → void:
if area.is_in_group(“Object”):
get_tree().change_scene("res://Level" + str(int(get_tree().current_scene.name) + 1) + “.tscn”)
When I run the project, the ball goes through the goal, but the level does not change. I have the signal connecting the Hitbox to the Sprite, and I’ve loaded the above scripts into the sprite. I have the sprite in each scene, connected to the Node at the base of the level.
Happy to provide more info, I hope I provided enough. I’m very new to this, assume I don’t know/understand. Thank you in advance!