0 votes

I'm making breakout.

I have a beta build here to show you what I mean:
Windows: http://www.video-games.io/games/beta/breakoutWin.exe
Mac: http://www.video-games.io/games/beta/breakoutOSX.zip
Linux: http://www.video-games.io/games/beta/breakoutLinux

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.

in Engine by (810 points)

3 Answers

0 votes
Best answer

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
by (810 points)
0 votes

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.

by (1,318 points)

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: https://godotengine.org/qa/13408/play-my-beta-and-help-me-with-a-collission-bug 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)

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.move(ball._movement*ball.speedIncrement)

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 ball.gd script, it's just easier I think :-) It's too large to paste here (over 8000 characters) so pasting here in pastebin: https://pastebin.com/Lw0csZRE

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.

0 votes

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.

by (7,796 points)

Thanks for the answer. I just turned on motionfixenabled 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.

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

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 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 webmaster@godotengine.org with your username.

Categories