Please play my game beta to help with this bug. Bat and Ball doing a strange vibration / collission / grab thing.

: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.

I’m making breakout.

I have a beta build here to show you what I mean:

What you need to do is play it for a minute, and try and get the ball to hit either extreme corner of the bat. The ball will then hug the bat, and start to rolll under the bat, rather than releasing.

Here are images of the setups:
enter image description here
enter image description here
enter image description here

The game will show you what I mean as it’s too hard to get a GIF to show it properly.

Any advice would be VERY much appreciated. Thanks so much.

:bust_in_silhouette: Reply From: YeOldeDM

Are you scaling collision shapes?

What’s the code for your ball? Specifically, the code which handles how it bounces?

What are these extra nodes on your bat? It looks like you have a kinematicbody as the child of another kinematicbody? That’s going to cause issues.

Showing off a broken build of your game isn’t going to provide us with much to help you with. A link to the project folder itself would be extremely helpful, not to mention a lot smaller of a download.

I suggest stripping out anything in your bat that doesn’t involve ball bouncing. Keep your testing environment clean and minimal, and it becomes much easier to solve problems like this.

Thanks for all your feedback. I’ll put in order here:

1 - I’m not scaling anything no.

2 - There are extra nodes int he bat for this reason: They don’t interfere with each other as they’re on separate physics layers

3 - The access to use the build was simply so people could witness the behavior. That was the idea of the usefulness of the shared game in its current, bug visible state.

4 - Good idea with stripping out everything bit by bit. I’ll also get some code here in the next comment to show you what’s happening. There’s a lot going on but I’ll try and focus on the important stuff (no powerups etc etc)

Robster | 2017-08-02 02:31

For the ball.
When we hit the bat, this is the code that deals with bouncing:

ball._movement = normal.reflect(ball._movement) * ball.bounce*1.2  
# add 20% as the gravity requires a bit more power to keep the ball playing well

When not hitting anthing (just flying through air) this is the code:


ball movement is setup in this function earlier on:

func launch(directional_force):
	ball._movement = directional_force

In the update this is how it’s setup:

ball._movement.y += delta * ball._gravity

Actually, here is the complete script, it’s just easier I think :slight_smile: It’s too large to paste here (over 8000 characters) so pasting here in pastebin: extends KinematicBody2Donready var state = #this crea -

Robster | 2017-08-02 02:42

I’ve stripped everything from the bat now. All there is, is a Kinematic, a sprite, a collisionShape. The bug still occurs. I’m totally stumped.

The code driving the bounce is ball.move(ball._movement*ball.speedIncrement) but it only bugs out when it bounces off the collisionShape at horizontal or below horizontal angles. I can’t see how that line can make that an issue.

Robster | 2017-08-03 10:42

:bust_in_silhouette: Reply From: eons

For the description, sounds like a move issue, could be common in kinematic vs kinematic.

Do you have the motion_fix_enabled option on?
Since 2.1.3 is in Project settings>Physics 2D.

Also, you may want to increase ball’s collision separation property a bit along with the speed.

Thanks for the answer. I just turned on motion_fix_enabled and I THINK it has helped a little but the issue still persists on certain angles.

What is the ball’s separation property? I couldn’t see any properties like this in the CollisionShape2D, nor the KinematicBody2D.

I assume you mean the faster the ball the … larger its collision shape radius? The only thing there is it happens even on the very slowest of speeds if I slow it down a lot.

Robster | 2017-08-03 10:04

“Collision margin” is called, is like how big is the separation after collision, changing it may help in some cases.

eons | 2017-08-05 22:23

:bust_in_silhouette: Reply From: Robster

This was answered on the Facebook group by a kind soul.

This is his code. I’m still trying to work out how it works, but it does work. For anyone in the future:

	var remaining = ball.move(ball._movement*ball.speedIncrement)
	if ball.is_colliding():
		var norm = ball.get_collision_normal()
		remaining = norm.reflect(remaining)
		ball._movement = norm.reflect(ball._movement)
		ball.move(remaining) # this extra move of the remaining movement vector should stop it getting stuck