Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Gisore |
Something’s wrong with my script.
i have 2 labels “Score” and “Lost Balls” on this project, somehow i got the func working with “Score” but “Lost Balls” would aways change the score to 1
goes like this:
extends Node2D
var score = 0 setget set_score
var balls = 0 setget set_score
func set_score(value):
score = value
get_node("Score").set_text("Score: "+str(score))
func set_bolas(value):
bolas = value
get_node("Balls").set_text("LostBalls: "+str(balls))
thats for the World Node script
and theres for the “Ball” node:
Working part (score)
if body.is_in_group("Brick"):
get_node("/root/World").score+= 1
body.queue_free()
and theres:
Probably wrong part (balls)
if get_position().y > 360:
get_node("/root/World").balls+= 1
queue_free()
Not sure how to set a Spoiler Tag, but here’s the full code:
extends RigidBody2D
export var SpeedUp = 20
const MaxSpeed = 1000
func _ready():
set_physics_process(true)
pass
func _physics_process(delta):
var bodies = get_colliding_bodies()
for body in bodies:
if body.is_in_group("Brick"):
get_node("/root/World").score+= 1
body.queue_free()
if body.is_in_group("Brick2"):
get_node("/root/World").score+= 5
body.queue_free()
if body.get_name() == "Paddle":
var speed = get_linear_velocity().length()
var direction = get_position() - body.get_node("Anchor").get_global_position()
var velocity = direction.normalized()*min(speed+SpeedUp, MaxSpeed)
set_linear_velocity(velocity)
print(str(speed+SpeedUp))
if get_position().y > 360:
get_node("/root/World").balls+= 1
queue_free()
pass
so, what I’m doing wrong? every time the Ball node falls from Y>360 the score goes back to 1