Play my Beta and help me with a collission bug?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Robster
:warning: Old Version Published before Godot 3 was released.

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.

:bust_in_silhouette: Reply From: timoschwarzer

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.

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…

Robster | 2017-03-23 23:44

:bust_in_silhouette: Reply From: eons

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)

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.

Robster | 2017-03-23 23:43