Hi! Im practicing developing a game that is the classic game were you move a bar and hit a ball to break bricks that are above it. Like arcanoid but with a ball, I dont remember the games name.
I have a player scene that has the bar(player that you control) and the ball scene in too. The idea is that i want to start the game having the ball “on top” of the bar and while the bar moves the ball stays “sitcking” to it untill I press Space. The space part i do it with a signal but im not able to see a way to keep the bar and the ball together until the Space is pressed. I can imagine this can be done keeping the ball inside the player node as a child, but i feel this is not a player child but and independent node that is going to not need to be related with the player but react to the player.
How can i link both nodes so they stay moving together until they Space is pushed?
Edit1: As is said in the first comment the ball is a RigidBody2D
Thank you very much! This is my first post so feedback is welcome, especially if im doing something wrong.
first you need to determine what type of node will this ball be
it looks like it has to be rigidbody2d for me,
if it’s rigidbody2d, then you can use freeze function and make it as a child of the player, and when you pressed SPACE, it will unfreeze the ball and you can add “push” power to it after reparent it back to world space
here someone done it in 3d, it’s “sticking” to player when the player is holding the ball
sadly the project file now is now deleted on this post, so you cant test it right away
Thanks for your answer.
The only issue i see is that i feel the ball should not be a players child, I see them as independent objects that should not be hanging one from the other.
Maybe im wrong and my programming experience with other languages and other environments is pushing me in a different way that is not the correct one.
becoming a child of a node is basically made them follow what the parent’s Transform is
since you want the ball to keep moving according to player position, then you can just make it as a child of the player and the ball has to be following the player around
reparenting isnt a big issues, it’s just basically 1 line of code now with the .reparent() function
there’s a best practices guide in the documentation, one of the pages mentioned about reparenting the player node before changing scene, so you dont have to keep instantiating each new player for every new scene, but i never read it’s a bad practice