Godot Version
4.3
Question
I am currently following a youtube video on how to make pong and am stuck on the scoring mechanic. I have an area2D object for the left and right borders of my pong game with the collision layer and mask set to 1 for both. The top and bottom borders are set at collision layer and mask 2 for both to avoid any unintended behavior with the borders colliding. My ball’s collision layer is set at 1 and mask is set at 1 and 2 so that it can interact with both the bouncing walls and the scoring walls. I made sure to connect the left and right borders to main.gd using the body_entered signal too. However, I noticed that the initial code I had, which was to update the score, did not function correctly. I thought it may have to do with the HUD update functionality or something so I added a print statement to see where the code was getting to. With the addition of this print statement, I came to realize that the function was not even running when the ball (staticbody2d object with collision layer set at 1 and mask set at 1 and 2) hit the left or right border. What could be the issue? Thank you for your help. Here is the code:
extends Sprite2D
var score := [0,0]
var PADDLE_SPEED: int = 500
func _on_ball_timer_timeout() -> void:
$Pong_ball.new_ball()
func _on_score_left_body_entered(body: Node2D) -> void:
print(body.name) # test to see what body is supposed to be (doesn't print)
print("hello") # print statement to check functionality of the code
score[1] += 1 # cpu score update
$Hud/cpu_score.text = str(score[1])
$ball_timer.start()
func _on_score_right_body_entered(body: Node2D) -> void:
print(body.name) # test to see what body is supposed to be (doesn't print)
print("hello") # print statement to check functionality of the code
score[0] += 1 # player score update
$Hud/player_score.text = str(score[0])
$ball_timer.start()