How do I bounce a jetpack off of 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’m trying to get my head straight on a few things that have me tied up in knots a little after moving over from Clickteam Fusion. I’m hoping I’m just missing simple things and am also not knowing the right wording for what I’m trying to find :^)

    I’m working with the platform behaviour, and the best way I can describe what I’m trying to do is, imagine the player has a jet pack!

    Once the player is airborne, you can press a button to fire the jetpack thruster and use left and right to move them, with a fair amount of floaty inertia.

    This is all absolutely fine and works well. But where I’m falling down a is, collisions with the scenery!

    What I’d like to achieve is, when you are flying, colliding with walls / ceiling will bounce you off. Not a fully elastic bounce, more like some of the impact velocity is being absorbed.

    My first thought was trying to record the x and y velocity at the point of impact and using these values to bounce you off, remove a bit of the actual impact velocity to make the impact feel better and also use it to subtract from a health meter of sorts, but I immediately hit a problem which was, I assume the platform behaviour has already seen the collision and stopped my player before my On Collision event fires, asking how fast you’re going (as it always returned 0).

    But then I figured this might not work very well even if I could get the values I wanted, for angled surfaces (probably mostly 45 degrees and 30 degrees as the game will have tile-based scenery). Working out the appropriate bounce angle out could get messy.

    I had read somewhere that maybe the bullet behaviour would be good for handling the bounces, and a quick experiment with just setting its speed and acceleration to 0, Gravity to 1000, setting Bounce of solids to true and removing Set angle, yielded quite decent results. The new problem(s) here are that I don’t see any obvious way to affect how much bounce actually happens and also, how I would possibly combine this with the platform behaviour or even make the bullet player controllable!

    I might just be going off on entirely the wrong tangent so I thought before I buried myself in this, I’d ask in here and see if anyone could point me in the right direction :^)

  • Bouncing by angle example: dropbox.com/s/hpqmn0yuatjyhff/bllt_bounce.capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There are a few ways you can go about doing the bounce. But since you are using the platform behavior it's easier to work around that.

    Here's one idea. It has a second object with the bullet behavior, that you update the position and velocity from the object with the platform behavior. Then when that bullet behavior object hits a wall, you can bounce and transfer the velocity to the other object. Seems to work reasonably well.

    dropbox.com/scl/fi/vfpccikywdi5itdvn5h4q/platform_bouncy.capx

    It may be possible to have both behaviors on the same object and do some juggling where the bullet behavior is mostly disabled and the platform behavior's velocities from the previous frame are saved into variables.

    You can also cut out the bullet behavior completely and do the bounce calculations directly. You'll still need to save the previous frame's velocities to variables. The main downside is you'll need to get the normal angle of the collisions which is something not provided by construct. There are ways to calculate it but for simplicity it's nice to just use the bullet behavior's bounce.

  • Thank you very much for the replies :^)

    alextro, sorry but i can't open your file for some reason (it says "Failed to open project. Check it is a valid Construct 2 single-file (.capx) project." when i try)

    R0J0hound very interesting! The thory is really rather clever :^) Unfortunately it seems to be a little unreliable in as far as sometimes, it just doesnt bounce. But i'll try and analyse quite why that is.

    Yeah, i had thought about maybe trying to work out the surface normal of the wall you're colliding with (though i don't really know how you'd do that in Contrsuct?) but i'd be stuck even befre that anyway as i simply cannot figure out how to record the collision velocity.

    In Fusion what i did was have two variables (one for x and one for y) that i updated constantly with teh x and y velocity. The condition for changing the variables was that the player was not colliding with the walls. That way i knew that when i WAS colliding, that variable was frozen for that frame at the speed it was travelling at immediately before the collision.

    But in construct 3, using the platform behaviour, it's like any event i try and trigger to freeze or capture the veklocity immediatly before or at the point of collision is firedc after the platform behaviour has already brought my player to a stop.

  • To record the collision velocity you’d put an every tick event at the end of the event sheet and set some variables from the player’s velocity there. This will give the velocity of the previous frame which is pretty close to the velocity when a collision happens. As you’ve already found out you can’t get the true velocity when you collide since the behavior already resolved it.

    The bounce is unreliable in my example for a few reasons. The bullet bounce action doesn’t always work well, using the previous frames velocity may not be good enough, and the platform behavior may be causing less bounce with how its internal logic works.

    To calculate the normal the most accurate would be a complex algorithm like SAT,Gjk, or Mpr as long as you can access the collision polygons of both. If you can approximate the player as a circle then another good way would be to represent the terrain as a SDF.

    Simpler approximate ways include doing a ray cast in the direction of the velocity before the collision, or sampling points for overlap around the player. Simpler still you could just sample four points around the player to see if you’re on the ground, next to a wall or below a ceiling. Then you could do the bounce if say you’re not on the ground, have a wall to your left and the x velocity is <0. Then you’d do logic similar for a wall to the right or above the player.

    It may also help to reduce the deceleration when in Jetpack mode so the motion is more floaty. There are probably more ways you can fiddle with the platform behaviors settings.

    Another idea which would take more work to do but give more control is to not use the behavior and do the motion with just events.

  • Ah yes there is a problem with missing icons. Should working just fine now.

  • Hey! Thanks for fixing it alextro :^)

    Ooh, very interesting indeed! I'd not really looked too much at the Custom Movement behaviour but it looks really quite interesting.

    The way you're getting teh angles for collisions is interesting too! Though i feel klike it wouldn;t be very practical in a tile based game.

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