bouncing physics sprite off walls

0 favourites
  • 7 posts
From the Asset Store
Bouncing ball
$9.99 USD
Template for a bouncing ball game, fully documented in comments and video
  • I have a physics based sprite that is moving around according to the direction its pointing and the impulse applied (currently I guess my sprite isn't rectangle so the impulse applied makes the sprite start rotating.

    not only that, i want to have the sprite bounce off the walls when it htis the boundary. Currently I did ad the Bound by behavior to the object...and it does stop the sprite but doesn't reflect it back...

    I am guessing there is a better way to do this?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here is an example where the walls are sprites with physics applied and Immovable property=Yes. You don't need the Bound by behavior. Just put the walls just outside the layout so they can't be seen and they will bounce the balls back into the layout. (Using bound by behavior seems to make the balls hang in the air, so I prefer just the walls.)

    The balls use Circle as the collision mask, and to make them bouncier set physics behavior Elasticity property to a larger number. (By default it is .2, in my example it varies between .5 and 1.)

    Click the mouse to make the balls bounce.


  • hey thanks for this this helps. What I actually have in mind...might not be possible.

    I want a huge world scrolling camera that follows the player (world limits makes u warp to the other side) but every so often LOCK the camera down with an artificial boundary (like the one you describe above) and have the player (and other stuff) bounce around with in it for a while... though not sure how I would figure out the edge of the current screen and add the solids there dynamically. But thanks for this post it helps!!! just gotta think in construct2 to land and figure out how to make things a bit more dynamic.

    Its really figuring out what the camera edges is...then think i could set the four solids to those extends on top bottom left right. NO clue how to do this.

  • This isn't hard at all. You'll use the ScrollX and ScrollY system expressions to figure out where the camera is centered and position the walls relative to that. Save the offset from that position for each wall at the start of the layout and then put them somewhere off camera. WHen you want them again, reposition using (scrollX-self.Xoffset, scrollY-self.Yoffset). Here you go--


    To make the walls and the balls appear, click the mouse. The walls disappear after a short time and the balls get away.

    Good luck!

  • Okay you are the man thanks! That is slick. I will incorperate this and try to figure out also how to get my ship to stop spinning when I add an impulse to it. If i make the collision a bounding box it works, but if i leave it as the rectangle then I cannot figure out how to get my center of mass to make it add the impulse to that...   They said in release 61:

    "Physics: entering 0 for an object's image point now means its center of mass, rather than the actual object origin. This is so applying a force at image point 0 does not cause the object to rotate, which is usually the intention."

    But I have that on a rectangle and it seems to still make it rotate.

    So still investigating this,b ut the wall stuff is EXACTLY what I need. TY!

  • Your welcome.

    Did you try setting Prevent rotation to Yes in the physics behavior properties? I don't see a way to do it as an action, only when you first create the object...

  • yah I did say prevent rotation, but I could see where other rotation bumps i would want it to rotate, just not when I add an impulse to it. But for now if i make it a bounding box instead of leaving it as what it loads in, (a rectangle) it seems to work fine for now. Thanks again!

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