This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hi all,

I am making Pong.

When my ball hits a bat, it works perfectly, as long as the bat is not moving.

If the bat is moving though, the ball pushes the bat backwards.

I'm hoping someone can play the Beta of the game, see what I mean and offer some advice?

My Ball is a RidigBody2D with a CollissionShape2D as a child. As shown:
enter image description here

My Bat is a KinematicBody2D with a CollissionShape2D as a child. As shown:
enter image description here

The bat movement code is like so:


The game can be downloaded in Beta for:

Note I haven't tested the Windows build.

TIP: To really see it in action, make one player a CPU player. This is because I have the CPU adding a bit of "spin" to the ball by moving quickly at the last second, just before the ball hits the bat. That allows you to see the problem amplified as the bat is moving so quickly at this point.

Any help would be GREATLY appreciated.

in Engine by (838 points)

2 Answers

+1 vote
Best answer

Without playing the game, I think your problem is like this

Your moving body needs to be different from the ball hitting body if you want to use move

I put that again here...

Do this:

KinematicBody2D (+script, same mask as wall layer if you use it to limit movement)
|-CollisionShape2D (if you use it to limit movement)
|-KinematicBody2D (same layer as ball mask)
by (7,954 points)
selected by

Thank you for your help (again).

That worked perfectly. It took me a bit of experimenting as it's a bit new to me but I now have one Kinematic controlling the collision with the wall (and handling movement) and another with the ball. No more ball pushing the bat. Great stuff, much appreciated.

+1 vote

It is because you move your bat with the move(<Vector2>) function which moves your body until colliding with something.
You could simple use set_pos(<Vector2>) to prevent this behavior.

by (713 points)

Thanks for the answer. I wanted to keep the move() function, so I experimented with the other answer and that worked. Appreciate your response though...

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.