How to code finish line in racing game

Godot 4

Hi! I try to make racing game, my car moves within the borders of tile map, but finish line is not working and I have no idea what I do wrong. All help is apreciated

main script (I switched variable rounds for a global variable but it didn’t do much)

extends Node2D

var rounds = 0
var win = 0

@onready var ui = $bumpcars_player/Camera2D/UI_end_scene


# Called when the node enters the scene tree for the first time.
func _ready():
	pass


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	
	if Global.racer_rounds  >= 1:
		win = 1
	
	if win == 0:
		ui.hide()
	elif win == 1:
		print("win")
		ui.show()
	else:
		print("lost")


func _on_meta_body_entered(body):
	Global.racer_rounds += 1 

Meta is area2D node that is my finish line, it includes colision2D node. Area 2D should be sending a signal to main script, but it’s not working quite right

i need you to ensure the following:

  • You have a finish_line and a car_body.
    • Does your car_body’s collision mask check for the finish_line’s collision layer?
    • One of your objects must have an “on_body_entered” signal that is processed
  • Please add a print statement inside your _on_meta_body_entered method to see if it prints out anything.

Right now I assume that

but finish line is not working

means the collision detection of the car touching the finish line does not work.
This means either the collision layers and masks are not correct, or the signal is not connected yet.
Please check if your method has the green signal arrow
grafik

1 Like

Can you show how the meta node is set up? Like, the node tree for it?

How do you connect the signal?

How is the car set up? What nodes does it use? Is it a body or an area?

1 Like

YUUUP the issue was colision layer! Thank you, I totally forgot to check it!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.