#Need help with Pong (very beginner)

1 messages · Page 1 of 1 (latest)

fading ibex
#

Hi, so i just picked up the engine and saw people saying to make Pong as a starter project and thought i should do that to meet the engine a bit. I followed the guide (https://docs.godotengine.org/en/2.1/learning/step_by_step/simple_2d_game.html) but when i run it everything is off-centered. The paddles cant go past half the screen and can go off screen. Ball also spawns in the wrong spot. (Im aware this might be a version issue but do not know how to fix it, anything appriciated thanks)
This is my script (character limit so cant paste here)
https://pastebin.com/vJk2ihvz

raw magnet
#

Well, at least one reason for things being weird is because you're using both centered = true and the offset on all of the sprite 2Ds. My assumption is that you clicked centered because of the tutorial, but then used the offset to line up the objects onscreen?

Let's get started by resetting offset to x = 0, y = 0 (keep centered = true since that's what we want) and then to line them up using position. Which is located under transform in the inspector (the section you sent screenshots in

fading ibex
#

Did it, its fixed now but the ball isnt moving anywhere, i'd guess thats a problem in the script?

raw magnet
#

I assume you're not getting any errors, so add this line right under var ball_pos = get_node("Ball").position
print(ball_pos)
It should print the same thing a bunch, so just tell me what it says

I'll also ask if this is the tutorial you want to follow? After reading the tutorial, I can see why this is a good start, but it's missing some of the main components of Godot functionality. Mainly, signals and scene usage. Once you finish this, you'll move on to something else that will make heavy use of signals, and instancing a scene. I can come up with some new solutions to make pong in a more updated way if that would interest you.

fading ibex
#

(320.0, 188.0)

#

which is the balls starting position

fading ibex
#

i saw the version difference errors with get_pos() and position so i did realise its an old guide but didnt think it would be missing that much

#

ah i found the problem, i put the

get_node("Ball").position = ball_pos

inside the if case. Now it works properly i just need to fix some paddle collision stuff and adding a Start input or something along those lines. Also about those solutions i would be very thankful, if you want you can DM them to me so we dont flood the ticket for no reason

raw magnet
fading ibex
#

this is a thing on the page but this is the only version it has, others just lead to a page not found

#

Im trying to redo the project with collision bodies now since i feel like it was unnecessary scripting in the first one

raw magnet
# fading ibex Im trying to redo the project with collision bodies now since i feel like it was...

Yeah. I definitely know what I'm doing over the next few weeks. There's no way that the most common game to recreate (outside of doom) only has the oldest version of the engine supported.

For what it's worth, use CharacterBody2D for the paddles, StaticBody2D as the boundaries, and an Area2D as the ball. You'll still have to use custom "velocity" for the ball, but that's only like, 4 lines of code from what you already have.

Do you mind if I "copy" the working code you have? It would be a shame to waste your effort, and I think it's great for comparing the differences I'm planning.

fading ibex
fading ibex
raw magnet
raw magnet
# fading ibex also i used collisionshapes2d (as a child of characterbody2d) for the paddles an...

When you move a static body with code, it teleports instead of interpolating. Think about it as being the very first thing calculated. Eg the ball will go to its new position, and then the paddle will go to its position, but it can't because the ball is already there.

You can use animatablebody2d instead, but it's very limited in its features.

If you can get rigidbody2d working, major props. The only issue with using that is because of the way it calculates forces, setting velocity manually is very sensitive. The workaround is to use forces and impulses, and that requires actual math to work well.

fading ibex