Wrong bounce direction from dynamic object



I’m making a simple mini golf game and I have issues with physics simulation. Basically in the game there is a ball which the player can hit and walls which are used to bounce the ball away, very much like in real mini golf. The ball gameobject has Dynamic collision object and the walls are built from tilesource and collision shapes for the walls are automatically generated by setting Collision image from tilesource Properties. Walls are built from 32x32px tiles and their collision object type is Kinematic.

Most of the time everything works as expected, but sometimes when the ball hits a wall it doesn’t bounce to correct direction; it actually bounces back to the direction it came from. And as I said, this only happens like 1/20 of hits.

My first thought was that there is something wrong with the way Defold simulates Dynamic collision objects so I changed the ball from Dynamic to Kinematic and wrote simple collision detection script to switch the direction of the ball as I desired, but quickly found out the same behavior continued. I also noticed that when the ball bounces to wrong direction the normal which I got from collision response was way of. So I rolled back to the original setup where the ball is Dynamic object.

I think this might have something to do with the automatically generated collision shapes of the walls. Because I have 32x32px tiles and all those tiles have separate collision shapes that means the walls are constructed from multiple small collision shapes. Maybe the ball is hitting a corner of a collision shape rather than straight side of it? Is this a bug or planned behavior?

If my assumption of whats happening is correct, is there a way around this problem? I really would like to use automatically generated collision shapes for the walls because it just makes my life so much easier if I have to build tens of different levels.



I had exactly the same issue detailed in this thread

The solution I used was to manually add collision areas to the level in large blocks - quite laborious and not ideal but it solved the problem.



Okay, good to know.

This solution will work with my current project, but what would be the correct way to make procedural maps if I wan’t to avoid this kind of collision problems? I cannot use automatic tilesource collision shapes and if I create game object based maps with 32x32px collision shapes this same problem will appear. And as far as I understand collision shapes don’t scale correctly if I use a factory to create game objects and use non uniform scale factor. So is there a way to create procedural maps with reliable collisions at the moment?

1 Like