Bounce player off the edge of the screen

Get help using Construct 2

Post » Fri Jan 11, 2013 11:03 pm

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. :)
B
8
S
1
Posts: 34
Reputation: 938

Post » Fri Jan 11, 2013 11:22 pm

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.procrastinator2013-01-11 23:24:45
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Fri Jan 11, 2013 11:39 pm

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.
B
8
S
1
Posts: 34
Reputation: 938

Post » Fri Jan 11, 2013 11:48 pm

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 ;)
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Fri Jan 11, 2013 11:54 pm

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.
B
16
S
6
G
2
Posts: 152
Reputation: 3,764

Post » Sat Jan 12, 2013 12:42 am

http://dl.dropbox.com/u/93047429/omegaRelayTest.capx

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!
B
16
S
3
G
3
Posts: 66
Reputation: 3,629

Post » Sat Jan 12, 2013 5:29 pm

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.

https://dl.dropbox.com/u/8938070/PegJam/gametest.capxkill0byte2013-01-12 17:31:34
B
8
S
1
Posts: 34
Reputation: 938

Post » Sat Jan 12, 2013 8:27 pm

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 ;)

OMEGA

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.procrastinator2013-01-12 20:31:01
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Sat Jan 12, 2013 9:40 pm

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!
B
8
S
1
Posts: 34
Reputation: 938

Post » Sat Jan 12, 2013 9:51 pm

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
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Next

Return to How do I....?

Who is online

Users browsing this forum: ETgirl79 and 20 guests