Newbie attempting a racing game - currently stuck on making checkpoints work

(Version 4.3)

Hello, thanks for reading.

I’m very much a newcomer to Godot and coding in general. I’m making an attempt at a simple racing game, and I’ve been using tutorials and example projects to assemble my game. Here’s a short clip of what I’ve done so far:

So far - the player can collide with objects, collect checkpoints (the score is counted in a game manager) and cross the finish line. There is a timer on screen which starts when the game runs, and stops when the player collides with an Area2D at the finish line.

There’s lots to learn and add to - but right now, I’d like the timer to stop when the player touches the finish line and when they have passed a certain number of checkpoints.

I’m not quite sure how to proceed from here - do I add code to the game manager or the timer itself? I thought about using a simple “if” statement to get the timer to read the score but wasn’t quite sure if that was the best method.

Here are the scripts I’m using:

Game manager:

Checkpoints:

Timer:

Thanks for looking.

Good job so far. I would suggest you to look into how Autoload nodes work, as you might want to change your GameManager node to an Autoload.

About your question - yes, a simple if statement on the timer node should be enough.

func _on_finish_line_body_entered(_body: Node2D) -> void:
	if game_manager.points >= 3:
		set_process(false)

Side node: I would also suggest to change this “3” here and in the GameManager script to a dynamic variable that counts the checkpoints at the beginning of the game, not hardcode it like that - it’ll be more future proof :slight_smile:

Thanks, I’ll give it a try!

Update: Yup, the code works perfectly. Thanks again.

1 Like