Hi,
I'm practicing game development by creating a Flappy Bird clone. I've tried to program everything without using sprites or assets. And have so far completed making the top and bottom pipes with a gap between them. Now, I'm trying to create an Area2D node between the pipes to create a score counting system. However, what I have programmed doesn't seem to detect the player entering or exiting it.
The logic I'm trying to implement is as follows:
1. The top and bottom pipes are created using KinematicBody2D and CollisionPolygon2D during runtime and added as a child of a Node2D called "Obstacles".
2. The Area2D is also created at runtime using Area2D and CollisionPolygon2D and added as a child of the top pipe to fill the gap between the top and bottom pipes.
3. When the player enters the gap the Area2D detects it and waits for the player to exit the area to update the score.
I've tried using signals to print something on the console when the player enters the area but there's no output at all. I'm not sure how to tackle this. Any ideas?
`func add_point_area():
pointArea = Area2D.new()
var pointAreaShape = CollisionPolygon2D.new()
var pointAreaPolygons = PoolVector2Array()
pointAreaPolygons.push_back(Vector2(topPipeCreationPosition.x - pipeWidth / 2, topPipeHeight))
pointAreaPolygons.push_back(Vector2(topPipeCreationPosition.x + (pipeWidth / 2), topPipeHeight))
pointAreaPolygons.push_back(Vector2(bottomPipeCreationPosition.x + pipeWidth / 2, topPipeHeight + gapBetweenPipes))
pointAreaPolygons.push_back(Vector2(bottomPipeCreationPosition.x - (pipeWidth / 2), topPipeHeight + gapBetweenPipes))
pointAreaShape.set_polygon(bottomPipePolygonPoints)
pointArea.add_child(pointAreaShape, true)
pointArea.monitoring = true
topPipeBody.add_child(pointArea, true)
pointArea.emit_signal("area_entered")
pointArea.connect("area_entered", $".", "on_area_entered")`
Here's my runtime scene tree.