extends RigidBody2D
# Variables for ball movement and speed
export (float) var speed = 500
var velocity = Vector2()
var increase_amount = 1
var contacts: int = 0
signal score_increment
func _ready():
# Set the initial velocity of the ball
velocity = Vector2(speed, speed).rotated(randf() * 2 * PI)
linear_velocity = velocity
func _physics_process(delta):
var linear_velocity = velocity
var new_contacts = get_colliding_bodies().size()
if linear_velocity.length() < speed * delta:
linear_velocity = linear_velocity.normalized * speed * delta
if new_contacts > contacts:
speed *= increase_amount
contacts = new_contacts
func _on_YarnMouse_body_entered(body):
if body.is_in_group("Paws"):
emit_signal("score_increment")
game.gd
extends Node2D
var score = 0
onready var score_label = $Timer # Make sure to set the path to your score label node
func _ready():
var yarn_mouse = $YarnMouse # Adjust the path to your YarnMouse node
yarn_mouse.connect("score_increment", self, "_on_score_increment")
func _on_score_increment():
score += 1
score_label.text = str(score)
I just want when my mouse collides with paws my score +1
To increment the score when the “YarnMouse” collides with “Paws,” your code is almost correct but needs minor adjustments. Ensure that
The _on_YarnMouse_body_entered(body) function is connected to the body_entered signal, and the collision logic is correct.
extends RigidBody2D
# Variables for ball movement and speed
export (float) var speed = 500
var velocity = Vector2()
var increase_amount = 1
var contacts: int = 0
signal score_increment
func _ready():
# Set the initial velocity of the ball
velocity = Vector2(speed, speed).rotated(randf() * 2 * PI)
linear_velocity = velocity
func _on_YarnMouse_body_entered(body):
if body.is_in_group("Paws"):
emit_signal("score_increment")
In your game.gd, make sure the score_label references the correct node, and it’s updated properly when the score increments.
extends Node2D
var score = 0
onready var score_label = $ScoreLabel # Update the path to your actual ScoreLabel node
func _ready():
var yarn_mouse = $YarnMouse # Adjust the path to your YarnMouse node
yarn_mouse.connect("score_increment", self, "_on_score_increment")
func _on_score_increment():
score += 1
score_label.text = str(score)
If $Timer is actually a Label node that you’re using to display the score, then you don’t need to change anything. However, if $Timer is a Timer node and not meant for displaying the score, you’ll need to update the reference to point to the correct node that shows the score, like this:
onready var score_label = $Path/To/Your/ScoreLabel
It’s important to make sure you’re referencing the right node for updating the score. If $Timer is managing time and not the score display, you should update the path to the correct score label node instead.
Ok, so none of them are getting called! How are you connecting the body_entered signal to the _on_YarnMouse_body_entered function? Perhaps that’s where the problem is.
bruh yes now its working — Debugging process started —
Godot Engine v3.5.3.stable.official.6c814135b - https://godotengine.org
OpenGL ES 3.0 Renderer: GeForce GTX 550 Ti/PCIe/SSE2
Async. shader compilation: OFF
colided
colided
colided
— Debugging process stopped —
But if my contacts report is 5 thats mean it will colide only 5 times ?