End level when ball hits the wall.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By THE HELIX

Hi I am struck with a problem in my 2D game;
I would like to end the level when the ball hits the wall.The wall is generated using tilemap.
I gave the ball area 2D .
Can I use “body_entered” signal for the ball ?

I guess you can use it. Haven’t you tried? I would just connect the body_entered signal of the ball to the end_level function of the root node or something.

p7f | 2018-12-07 16:05

:bust_in_silhouette: Reply From: shield

You can, if the wall is a StaticBody2D.

onready var tilemap = $"../Tilemap"
connect("body_entered", self,  "_on_body_entered")

func _on_body_entered(body):
    if body == tilemap:

Can be static, kinematic or rigid.

The “entered” word sounds weird on rigids but means a collision, not an overlap with another body.

Oh, and the body must be monitoring and with contacts reported > 0.

eons | 2018-12-08 20:23

Your advice works for the ball if it’s a RigidBody2D.
The ball is an area2d though, so I use body_entered

shield | 2018-12-09 03:35