Bounce player off the edge of the screen

0 favourites
  • 13 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • Hi there...

    I'm currently working on a fairly simple game, and I'm trying to set it up so that the player will bounce off the edges of the screen, and have an invisible wall "light up" on contact. If any of you are familiar with an old game called Omega Race, you'll know exactly what I'm talking about.

    I've tried adding the bullet behavior and setting the "bounce off solids" setting as suggested elsewhere in this forum, but it doesn't seem to work. I also currently have the "bound to layout" behavior added, so maybe I'm going about it the wrong way? But any help would be greatly appreciated. In the meantime, I'm going to work on my art and sound assets. :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You could do it easily with the Physics object. Have you tried that yet?

    And how does the bullet behaviour not work? What does it do? Not bounce correctly? Have you edited the collision polygon? It's a bounding box by default. Go into image editor, and click the polygon tool at the very bottom of the toolbar on the left, then you can add new vertices and move them to fit your shape.

  • I haven't attempted to use the physics stuff yet. So far I've just been using the Custom Asteroids Movement example as a base, since it's the same kind of movement for this game. I'm a total and complete newb when it comes to C2, other than going through the beginner's tutorial and reading through the Asteroids in 100 events tutorial.

    As for what happens, when the player sprite hits the wall it just stops. It doesn't bounce at all. What I want it to do is have the sprite bounce off in the opposite direction.

  • It sounds like you didn't enable "bounce off solids" in the object properties. Click the object that has the bullet behaviour applied to it, you'll notice the property "bounce of solids". It's set to "NO" by default. Change to YES ;)

  • Hello kill0byte!

    Omega Race was cool; if you're doing something like that, best of luck man!

    As for your question, one way that might work (haven't tried it though) is to change the player's angle on contact with the boundary. If facing right is 0 deg, straight up is 90 and straight down is 270; when they contact the boundary, add or subtract 180 deg based on their current angle. If it's it too radical, modify the numbers to suit how you want it to look. Essentially, you want to reverse the direction of movement right?

    Another possibility: Do you have an invisible wall set up at the edges? If not, create a simple line sprite and set it to solid; you can put the opacity at 0 so it's not seen in the game or just set it to invisible at the start. If you have bounce on solids, the behavior should appear when the player contacts this unseen boundary.

    Take care, dude.


    So here's a kind of half-working CAPX to get you started.

    I can't seem to make the animations go back to their original frames once they have already been hit - maybe someone else will be able to solve this dilemma for me/us. It's been driving me crazy in my own projects too, and I'm sorry I couldn't do more!

    I just checked out the youtube for omega race - if you want an invisible wall, make the starting frame of the animation blank. Then, on collision, add a wait command once the next frame has been triggered, for a second or so, then have it go back to the original frame. I have to step out but I'll post a capx of what I mean in a bit.

    Hope it helps!

  • Ok, I tried creating some simple line wall sprites, gave them the solid behavior, and re-applied the bullet behavior with bounce off solids turned on but the ship flies right through the walls regardless. I'm posting my capx file here to show what I've got so far.

    And thanks for your help guys, it's much appreciated.

  • You were using custom movement for the player, and could've used custom movement -> reverse on a collision, but it would look wrong.

    Here's a modified physics version, with working flashy walls ;)


    Oh, I forgot to mention.. player around with the player's elasticity properties in the properties bar to control the bounce.

    I also edited the collision polygon to be a triangle rather than a square.

  • Thanks procrastinator! That works pretty much exactly as I wanted it to, and looking at the event sheet I can actually understand what's going on so that's super helpful.

    One quick question: I noticed when the ship turns, you have it set to rotate by 125 * dt. I'm assuming dt is delta time, but is that necessary? I understand that dt helps make things time consistently between different devices, but I'm not sure really how it goes about doing that so if you could explain why you did that it would be helpful, thanks! <img src="smileys/smiley1.gif" border="0" align="middle" />

  • um mate, that was in your original capx... I didn't add that ;p hahah

    but yeah, dt is to make it run the same on all devices. Without dt, if you moved an object 10 pixels per second, on slower devices it may run 4 pixels per second and on faster devices it could run at 20 pps.

    DT Explained Very Well Here

  • Thanks! <img src="smileys/smiley1.gif" border="0" align="middle" />

  • No problem. Hope all is working out for you! :)

  • Yeah. I'm still trying to figure how to implement everything - and I'm trying to think ahead and design with the idea of porting to mobile devices from the get go... but getting stuff from inside my head onto the screen is sometimes more difficult, lol.

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