dulvui / ball2box

Casual ball game created with Godot Engine for iOS, Android, Linux and Web
https://simondalvai.org/games/ball2box
GNU Affero General Public License v3.0
39 stars 4 forks source link

Wrong bounce on edges of boxes if near a corner? #10

Closed d-albrecht closed 1 year ago

d-albrecht commented 1 year ago

Given that you mentioned you are going to create separate tickets for my previous mega-issue, I thought that I would just create a new and dedicated one for this new finding. I'm playing level 118 a lot recently, and the level consists of a lot of axis-aligned cubes, so there are a lot of perfectly horizontal surfaces.

Now what sometimes happens is that the ball is bouncing up and down on the same box a few times. But the ball isn't stationary but slightly moves to one side with each bounce. But as soon as the ball gets close enough to one of the corners, it starts to accelerate back in the opposite direction. I haven't observed that yet but theoretically it should therefore be possible that the ball is jumping on a box for some time while simultaneously moving back and forth (left and right) a bunch of times.

Based on my limited knowledge on collision-detection and speed-running of platformers like Super Mario Bros. I suspect that your engine or your own collision code detects two collisions at the same time: at first a collision with the horizontal surface that makes the ball bounce up again, and then also a collision with the vertical surface of the cube the ball is bouncing on. But this second collision physically doesn't make sense (as the ball can't touch the side wall while at the same time bouncing on the top surface), still, could happen because games/engines only calculate what happens after some predefined step interval. And if the player moved into some object in the meantime due to its inertia, the engine applies some force to move the player back out of the object it collided with.

I'm pretty sure that this effect isn't caused by ball rotation. I know that you consider rotation at least sometimes. If a ball rolls it actually shows rotation of the sprite. Not sure if a ball can gain rotation due to a collision or if the bounce back from a collision can be affected by rotation (see for example spin in games like table tennis). Either way, whenever I observe this, the change of direction comes so suddenly, that spin can't be the explanation here.

I hope my description was clear enough so that you know what I'm talking about. I wasn't able to record this (or didn't want to record for several minutes in the hope that it happens again) and I'm not that good at sketching this accurately in some graphics software.

dulvui commented 1 year ago

Thank you for taking the time to write so detailed issues! I really appreciate your effort.

You are right again, the ball bounces sometimes in unexpected directions, because the ball moves in a flat 2d way but in a 3D world. I realized this by blocking the ball to move on the z-axis. So the ball can only move up/down and left/right but not to or away from you. The problem here is that as you already mentioned, the spin of the ball, because he still can rotate on the z-axis direction. So if he does so, the ball movement can result strange. I see here two possible solutions:

I'll try both an keep you updated if and how the fix will work.

dulvui commented 1 year ago

I implemented "Limiting the z-axis rotation" and seems much better now. Update is avaiable on App Store, Google Play Store and itch.io F-Droid update will be available in the next days

dulvui commented 1 year ago

Now the update is available on all platforms. If it still seems weird, please let me know here and I'll reopen the issue.