How do I keep the ball inside the box?

0 favourites
  • 4 posts
From the Asset Store
Enjoy the powerful simulation with accurate ball physics, build with realistic ball spinning animations
  • I have an enemy that bounces around a confided area, but after a little while it breaks and phases through the wall, and escapes the box. Is there anything I can do to prevent the enemy from escaping the box?

    I've attached a photo of the collision areas of my confined space. I don't think its the overlapping bit causing the problem because it escapes from all sides.

    The enemy just has solid and bullet behavior and is set to bounce when it collides with a solid object(the box).

    any insight into what is goin on would be helpful

  • You can make the walls thicker and/or reduce the speed of the ball.

    Motion is an illusion, objects move by teleporting a bit each frame which can cause collisions to be missed. What’s probably happening in your case is the collision response is struggling with that particular collision polygon so it’s perhaps pushing out in the wrong way.

    Anyways another idea could be to clamp the balls position inside the box. Something like

    Set x to clamp(self.x, box.bboxLeft+radius, box.bboxRight-radius)

    And do the same with y with top and bottom.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can use an invisible, thicker wall if aesthetics is a concern, and show a visible thinner wall over it.

    Depending on which behavior you're using, there may also be a "stepping mode" you can enable to bypass this problem at the cost of CPU performance.

  • Adding a second, thicker wall has fixed the problem. Thank you guys for your suggestions and explanations. Much appreciated! oosyrag R0J0hound

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