There is a bug with collisions in my game

Hi, I have a problem with my player. Sometimes a bug occurs where my player gets stuck on other objects (rectangles). My player, as shown in the code, moves forward and the gravity of the player can be changed by touch. The bug sometimes occurs when my player hooks onto the corner of a square or rectangle. I used toggle_physics_debug to see how I could fix it. I tried to change the collisionobject values to see if this could resolve the bug, but it didn’t (I was changing values such as Friction, Restitution, etc.). I also tried to modify the code to push the player a little bit if a collision occurs, but still nothing. I even tried to add little spheres on the corners of rectangles because I thought my player could get stuck on the “sharp corners” of the rectangle, but still nothing. I have attached screenshots of my player.script, screenshots of my game with toggle_physics_debug enabled, and also how my player and rectangle look. My game is live on the Google Play. I will also attach the link to the game so that you can see more about how my game looks and have better context. You don’t have to download the game (it contains ads), but there is a short video which can give you more or less an idea of how my game looks. The bug occurs not very often, but when it does, it’s Game Over for the actual player who plays the game. I am out of ideas on how to fix it, so I am asking for ideas on how to resolve this issue. Sorry in advance if this is some kind of dumb/easy-to-resolve bug, but I have no more ideas.

Link to the live game on Google Play: [https://play.google.com/store/apps/details?id=com.Smiler.GravityPlatformer](https://Gravity Platformer)



This is not a bug. You shouldn’t use go.set_position in physics world. It mess the physics calculation. If you want to move your objects, you have to use ‘force’. (Use the force Luke)
And please use code fences when sharing a piece of your code. It is hard to read from a image.

I have the same issues too with defold. I was told to use force and it still happens. I don’t know of a reliable way to use collisions in Defold yet. I’m hoping to find one though so I’ll be following this thread.

Hey, for fast collisions I think you get a better result if
you enable that collision body as bullet or something like that (on the editor).

Edit: nvm it was mentioned already

Is this reported on GitHub? I would like to take a look if you could share a project where i can reproduce it.

Actually this not a Defold related issue, it is basically because of the wrong usage/understanding of the physics world. It doesn’t matter which engine you are using. There isn’t a magical solution that prevents tunneling issue(actually it is not an issue, it is a bad usage of simulation).

Just by looking at your video, I can say that you are constantly adding lots of force to the ball. Which cause the ball to move a lot in a frame time. There is nothing going to magically happen to stop the ball if it pass the collision object in a single frame. You might try to limit the force.

Good pinball collisions are not easy and I’m pretty sure none of the good pinball games out there are using physics engines. Most of them have their own collision detection algorithm. (simple video: https://www.youtube.com/watch?v=NhVUCsXp-Uo or famous windows pinpall)

Wtih a simple search for ‘pinball collisions’, you can find tons of tunneling issues for tons of different game engines because they all try to use physics engines. Physics engines are complex physics world simulations and in my opinion, big percentage of 2D games doesn’t require to use physics engines at all(None of the C64, Amiga or old PC games using it.).

In @Smiler case, it is a very bad practice to use complex physics simulation engine to detect a bird hitting the walls :slight_smile: Simple AABB test is going to be more than enough(and going to be faster, and small file size).

3 Likes

Yes there is a lot of force being applied. It was one of the game mechanics I was hoping to use…where the player can change behavior during the game so I was testing things out.

However, I was told that I should use physics in pinball by @britzl. He may not have understood I wanted to have the possibility of using a lot of force.

So how does one do this type of thing in defold? Or do they have to write a custom engine? Based on the video it appears I may have been better off using the collision objects then handle the exceptions manually instead of relying on 100% built-in physics.

Or use my own module to handle this. I appreciate the video you shared as it gives me good insight on how to handle this.

He is right, you can. There is no problem using physics. It is easier to use built-in stuff. You can limit the force or you can also implement a ray cast to prevent the tunneling.

Your ideas foundation has a flaw.

What type of thing? Why do you want to use such a large force, players cant even see the ball. What is the point of developing a game which no one be able to success. There isn’t such a limitation on Defold to build any kind of a game.

It is up to you. Do your own test, make your decision. AFAIK none of the solutions available is going to handle this kind of a balls speed, unless you find a other workaround or faking it.

The video you shared clearly shows what to do when the ball tunnels. You apply a force opposite to it. Heck I might even be able to do it with the existing physics engine.

Also if an engine can’t keep up doesn’t mean the idea is flawed. It just means the tech isn’t there yet. It’s stuff like this that push engineers to keep improving engines and solutions.

You might try if you can catch the ball :slight_smile:
ps: physics engines already do that(CCD/Bullet). Your problem is beyond that.

Well, I spent the day learning unreal blueprint. And I tested with unreal giving a ball a huge amount of force…and guess what? It shot right through the wall. LOL. So I guess if Unreal can’t do it, I shouldn’t expect defold to do it. :slight_smile:

This is not related to Unreal, Defold or any other engine. I did try to explain to you before, go ahead and read them all again. Wish you luck on this journey of yours.

1 Like

I had to check for myself.

Some things I’d try to do:

  • Put a limit to the velocity. Do not apply more force if your linear velocity is above a certain treshold
  • Perhaps do some prediction using ray casts to know if you are about to collide (and do “something”)
  • And apply an opposite force on collision to fight tunneling
3 Likes

@selimanac @britzl

Ok, I just got back to my pinball game and guess what? It no longer tunnels. There was an update on my defold engine…I wonder if that fixed it?

Also i noticed that if I use fixed timestamp in 2D the debug physics blinks a lot. But if I turn it off the debug physics looks good. For the record it didn’t tunnel regardless of fixed timestamps setting. So it does appear something has changed to improve the physics collisions. :slight_smile:

Fixed timestamp (BTW: at the end of this video you can clearly see the physics are working great as the ball gets stuck going back and forth and no tunneling):

No fixed timestamp (Notice no flickering of the debug physics objects):

Yes, this is a known bug Physics Debug rendering bug · Issue #7617 · defold/defold · GitHub

2 Likes