I recently finished my first Godot project after about a week of learning Python. It’s based on Brackeys’ beginner tutorial, but I experimented with a few things on my own (such as enemy ledge detection, UI changes, and some other small modifications).
I’m mainly looking for feedback on:
Project structure
GDScript style
Things I should learn next
Any bad habits you notice early
I also have one question about the Audio Bus system. I describe the issue in the README, but in short: I created separate Bgmusic and SFX buses, yet only the Master bus seemed to affect the audio. If anyone can point out what I misunderstood, I’d really appreciate it.
Repository:
Thanks for taking the time to read it! This is also my first github repository, I am not even sure if i pronounced it right lol!
I don’t usually use GDScript, but I can give you a few generic pointers that, in my opinion, will help you in the long run.
For one, doing things like this:
@onready var game_manager: Node2D = $"../../theknight/Game Manager"
Can get very confusing really fast. When you need to get a reference to a node, I highly recommend using @export instead, since even if you move your nodes around, the reference won’t break.
I noticed that you’re a bit inconsistent with declaring variable types, such as here:
const SPEED = 60
var gravity: float = ProjectSettings.get_setting("physics/2d/default_gravity")
var direction = 1
@onready var ray_cast_right: RayCast2D = $RayCastRIGHT
It’s a good idea to get into the habit of declaring every variables type, it helps with future debugging and also helps a tiny bit with performance.
In some cases, you don’t need to use two different if statements at all, a good example is here:
if direction > 0:
animated_sprite_2d.flip_h = false
elif direction < 0:
animated_sprite_2d.flip_h = true
You can simply do:
if direction != 0:
animated_sprite_2d.flip_h = direction < 0
Hi, first of all thank you for taking your time and helping me. When I used export instead of the onready on the game_manager part, It would cause a glitch that makes the game crash the second I collect the second coin, the glitch message is:
That is by changing nothing else but the @onready to @export.
For the direction recommendation: Thank you so much, I had a rough idea I was too repetitive but I wasn’t sure how to fix that. It works as u showed on the picture and is helpful! I believe the idea there is do nothing if direction is 0, and if direction is -1, basically less than zero, flip the sprite as it would be moving on the -x axis, or simply left.
Though for the declaration of variable types can you show a simpler example, though I know the gravity is kinda complex cuz i didnt know the number and copied from the base text from the player and some stuff from the godot documentation!
Just changing it to @export is not enough, you need to go back to Godot’s inspector and actually select the node in there. Otherwise godot won’t know WHICH node you want to bind to that specific variable.