Godot Version
4.3 stable
Question
Hello!
I’m learning Godot by making a breakout clone.
I have the paddle as a CharacterBody and the ball as a RigidBody. I got everything working great in terms of the ball hitting static bodies and rebounding correctly.
Then I added a Camera2D to follow the paddle, and made the paddle move up slowly using move_and_collide().
After doing that, now, every time the ball hits the paddle, the paddle moves ever so slightly down (so that after a few dozen collisions on the paddle, the paddle has moved noticeably down-screen).
What’s weird is that it doesn’t do that when the paddle is not moving.
Any help would be greatly appreciated! =)
What is your motion mode set to?
Hi! =)
I’ve tried both Floating and Grounded and both ways does the same thing.
I think I understand that since I am using move_and_collide to make it move up really slowly, that function is calculating some sort of collide when it hits something. So maybe there is some way of moving the paddle up without using move_and_collide?
How does move_and_slide() performan?
Ok, I solved it! Although I’m not really sure I understand how, lol.
I was moving the paddle up slowly with this:
velocity = Vector2(0,-1) * delta * arkMoveSpeed
move_and_collide(velocity * delta)
which after trying many different things, I changed to this:
velocity = Vector2(0,-1) * delta * arkMoveSpeed
var arkcoll_info = move_and_collide(velocity * delta)
if arkcoll_info:
velocity = velocity.bounce(-arkcoll_info.get_normal())
and now, the paddle moves up slowly and does not get slightly displaced when the ball hits it.
Do you understand why? lol
Thanks for answering me here.
PS - to answer your question, I thought of move_and_slide() but it seems not to accept any parameters, so didn’t know how to tell it what to do.
To answer no, i don’t understand why it does that. My understanding it shouldn’t move like that unless you may have done something weird in code.
And looking at your code your paddle shouldn’t worry about collisions as the rigid body will take care of itself. All you need to do is move the paddle left or right. If you want more control you should use a characterbody2d for the ball as well.
It reacts to your velocity and static collisions.
1 Like
Ok I definitely need to figure out how to use move_and_slide hehe (I used move_and_collide to do the sideways movements (when giving an input) too)
Anyway, thank you for your replies. First time using the forum, but definitely won’t be the last =P