This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I'm trying to create a score to make a pong game but the player's score starts at 2 and the enemy's at 1 when I put 0 in the variables

extends Node

var playerscore = 0
var oponentscore = 0

func onmetaderrotabodyentered(body):
$pelota.position = Vector2(640, 360)
$oponent.position = Vector2(1243, 364)
$jugador.position = Vector2(44, 364)
oponentscore += 1
get
tree().callgroup('pelota' , 'stoppelota')
$Timer.start()

func onmetavictoriabodyentered(body):
$pelota.position = Vector2(640, 360)
$jugador.position = Vector2(44, 364)
$oponent.position = Vector2(1243, 364)
playerscore += 1
get
tree().callgroup('pelota' , 'stoppelota')
$Timer.start()

func process(delta):
$playerscore.text = str(playerscore)
$oponentscore.text = str(oponentscore)
$Timer.text = str(int($Timer.time
left))

func onTimertimeout():
get
tree().callgroup('pelota' , 'restartpelota')

in Engine by (12 points)

1 Answer

0 votes

Are You sure bodies other than pong ball aren't colliding with goal fields ? ;) Like players ? ;)
You can always add condition under those two signals to ensure only ball triggers collision :

func onmetaderrotabodyentered(body):
        if body == get_node("Ball") #path leading to your ball

or:

if body is ball #if You made ball a class
by (8,188 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.