My first game in Godot - Pong, how'd I do? Plus a question on bouncing

Godot Version

4.3

Questions

  • What can I do better?
  • I found “velocity = velocity.bounce(collision.get_normal())” in the documentation for how to make objects bounce, but I don’t quite get how it works. Is there a more detailed write up on it for beginners?

Link

I made this in about an hour after having watched a few tutorials on gamedev tv, I think I did okay with it given the time constraint and the fact I only used the documentation. Is there anything I can improve? I don’t want to start my Godot journey with bad habits

1 Like

17356070352333740940627356702537
Velocity is the black arrow, the dotted arrow is the normal vector you provide in the bounce call.

In physics the angle of incidence is always equal to the angle of reflection.

The scripts are nice and small and putting game code in the ball is convenient, but overloads the responsibility of the class.

If you wanted different game modes that could have extra balls you wouldn’t want more then one instance of the game logic flying around in the scene.

1 Like

Just curious, did you follow the original Dodge the Creeps 2D tutorial? I found it was a great start :slight_smile:

Hey this is pretty cool!

One really helpful thing that you can do is to export variables to avoid situations where you have “magic numbers” in your code. A “magic number” is essentially a number that is hard-coded into your script with no easy way to alter it other than by going in and altering the script. If you keep up with your gamedev.tv course, they’ll probably talk about those a bit.

So for example, in your code you have the following line to set the speed of the player’s paddle:

const speed = 400

but, you can actually make this value changeable in the editor itself by doing this:

@export var speed = 400

which results in the value showing up here:


Very handy for these sorts of gameplay-oriented values!

Thank you all for the replies!

pennyloafers thank you, that clears things up a bit for me. As for the classes, I figured I’d need to use them at some point :sweat_smile:. Would I just move the entire _physics_process function to a class and grab all the balls in the scene and keep track of them like that? Maybe a ball_manager script?

mark-wiemer I did not, but I’m going to look into it - thanks!

TK_W Oh yeah, that makes sense. I should have @export’d the speed, I just kinda threw it together to see if it’d work but I guess even in a project like this it’s good practice to get into, thank you!