How to prevent it?: Objects pass through other objects despite collision polygon (small collisions).

0 favourites
  • 10 posts
From the Asset Store
Assets for creating mountains and ravines environments
  • Hi

    I have 2 objects:

    - box

    - balls (many instances inside of the box). Important: balls have smaller collision polygons than their size (approximately 30% in the center)

    Box has Physics (Immovable) and Solid behavior.

    Ball has Physics and 8Direction behavior (for interaction with solids).

    When I fastly rotate a box (or when the box hits the edge of layout) balls pass through it despite collision polygons. How to prevent it?

    Thanks.

  • Only use the physics behavior, and there’s a continuous collision detection check mark I think.

    Physics doesn’t work with other behaviors.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Currently, only have thoughts about adding very wide invisible rectangles (with solid behavior) as a child to the box walls.

    Perhaps there is a better way to implement this?

  • Only use the physics behavior, and there’s a continuous collision detection check mark I think.

    Physics doesn’t work with other behaviors.

    I've already tried to use only Physics behavior for box and balls but it does not work. When I change the angle of the box, balls pass through the box walls (despite collisions and Immovable mark).

    Adding 8Direction behavior to the ball and Solid to the box allows keeping balls inside of the box when I slowly change the angle. But if I change the angle fast, balls still pass through the box walls.

  • Only use the physics behavior, and there’s a continuous collision detection check mark I think.

    Physics doesn’t work with other behaviors.

    This would probably work if the balls had the size of the collisions as the width of the Sprite. But for my purposes collision polygon of the ball is smaller than Sprites width and height.

  • For physics to work best you'll want the motion of objects to only be handled by the physics behavior. Any other behavior will interfere. Also at no time use set position or angle. You can set angular/linear velocities, apply forces or impulses to move things.

    For something like a rotating box you'll need to do that with joints to put it together. Then with the "bullet" setting the balls will bounce off walls no matter how thin.

    dropbox.com/s/yh0tj716maey831/continuous_collisions.capx

    Of course you still can overpower the joints at times, but usually it's stable.

  • For physics to work best you'll want the motion of objects to only be handled by the physics behavior. Any other behavior will interfere. Also at no time use set position or angle. You can set angular/linear velocities, apply forces or impulses to move things.

    For something like a rotating box you'll need to do that with joints to put it together. Then with the "bullet" setting the balls will bounce off walls no matter how thin.

    https://www.dropbox.com/s/yh0tj716maey831/continuous_collisions.capx?dl=1

    Of course you still can overpower the joints at times, but usually it's stable.

    Thank you for your example.

    I use a slider to change the angle of the box (with a limitation of movement between 0 and -120 degrees). Also, my box is a full-piece sprite. Balls have small collisions (as mentioned before).

    My brain is blowing up how to do it only using Physics behavior.

    GIF Image

  • Here's one idea:

    Attach the bowl to an immovable physics object with a revolute joint.

    Then change the angular velocity to turn toward the angle you want.

    Details with some more explanations:

    dropbox.com/s/fp0hrl9f73f10yh/physics_rotate_bowl.capx

    In general think of setting angle or position of physics objects as the same thing as teleporting. In your example you set the angle directly so if you rotated the bowl object fast enough the balls could suddenly be on the other side of the walls of the bowl. The physics engine won't think the balls went though the walls.

    However when setting velocities the physics engine can do it's magic to avoid jumping through walls. Especially if the "bullet" setting is enabled which does continuous collision detection.

  • Here's one idea:

    Attach the bowl to an immovable physics object with a revolute joint.

    Then change the angular velocity to turn toward the angle you want.

    Details with some more explanations:

    https://www.dropbox.com/s/fp0hrl9f73f10yh/physics_rotate_bowl.capx?dl=1

    In general think of setting angle or position of physics objects as the same thing as teleporting. In your example you set the angle directly so if you rotated the bowl object fast enough the balls could suddenly be on the other side of the walls of the bowl. The physics engine won't think the balls went though the walls.

    However when setting velocities the physics engine can do it's magic to avoid jumping through walls. Especially if the "bullet" setting is enabled which does continuous collision detection.

    Thank you so much for your explanation and example.

    Changed collision polygon for Ball in your example, spawn 100 balls and on fast speed slider dragging (right-left) some balls can pass through the walls or stuck inside despite only Physics behavior.

    If I enable Bullet setting for the ball or bowl (continuous collision detection), mass of balls pushes the bowl down (bowl flies down). How to prevent it?

  • I guess you could give the bowl more mass or the balls less.

    If the balls are still leaking through then you are running into the limits of what that particular physics engine can do. Probably need to reduce speeds and make things move more gradually like changing the 10 to a smaller value. That or make things bigger. Those things and my precious suggestions in theory should help prevent objects from passing through each other.

    I think overall the physics engine was made to be general purpose and work pretty well. It is possible to break the simulation pretty easy though. When that happens you just have to dial things back I suppose.

    Reduce speeds, enlarge objects, make the masses more similar. Might be able to make it run better by increasing the iterations of the simulation. There’s an action for that. Not sure.

    The alternative is to scrap using the physics behavior and just devise a way to keep the balls from moving through walls with raycasts or something. The con of that is the rest of the physics would need to be done too. I don’t really think a hybrid approach would be any easier than from scratch.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)