How do I quickly and easy figure out which side of a sprite.

Get help using Construct 2

Post » Thu Mar 05, 2015 9:50 pm

Hello.

On collision with a sprite, how do I figure out which side of the sprite another sprite (ball) is colliding with?

For example if the ball is hitting the bottom edge of a sprite. Or its left..

Should work with sprites that are generated dynamically and not slow down with hundreds of sprites on layout.

I am open to plugins if it shorten down the coding.

Something like @rexrainbow 's Boundary but externally and not clamping/wrapping. :)
B
58
S
18
G
13
Posts: 447
Reputation: 10,735

Post » Fri Mar 06, 2015 12:48 am

You could use
"Is Overlapping at Offset" (-25, 0) for left side
"Is Overlapping at Offset" (25, 0) for right side

and make it a dual condition by adding System> Trigger Once while True to each
Image
B
75
S
23
G
3
Posts: 673
Reputation: 9,273

Post » Fri Mar 06, 2015 2:45 am

With big offset it looks like the ball is bouncing mid air. So I l lowered to 2 px offsets only. It works in slow but when on low spec or high speed it would be less exact. hmm.
B
58
S
18
G
13
Posts: 447
Reputation: 10,735

Post » Fri Mar 06, 2015 3:06 am

You should explain what you are trying to make here. Set up the scene for us and we can probably offer a simpler solution.

Also, include a capx or screenshots.
B
53
S
14
G
13
Posts: 818
Reputation: 17,424

Post » Fri Mar 06, 2015 3:23 am

@techniko

I wanted to make a more reliable breakout style game or just ball/ricochet that would bounce off in proper angles and not fly off randomly. (all in the style of 70-early 80s era game) Also not escaping the play field.

For the not escaping play field I used rexrainbow plugin Boundary which works nicely.
For the better, more predictable moving of the ball/bullets I used custom movements instead for bullet. It is so much better!! (the "Reverse custom movement" for example to switch the angle)

The goal is indeed to have a good code even for high speed or low spec computers.

Here's a capx just be aware you have to have Boundary plugin.

Use shift to add ball, you can add more balls. The paddle's top will change the ball's angle.
Left/right arrow to move the paddle.

Spacebar to pause game, enter to unpause.

Try add 10+ balls in this game and study how the balls starts to go through the blocks.
(wait with the first ball until you got the screen filled with at least 100+ blocks)
You do not have the required permissions to view the files attached to this post.
B
58
S
18
G
13
Posts: 447
Reputation: 10,735

Post » Fri Mar 06, 2015 3:32 am

I think you are over-thinking this project. I made a breakout game a few years ago and I did not need any plugins or custom movements. Unfortunately, I can't offer much more help then that. I don't want to install plugins.
B
53
S
14
G
13
Posts: 818
Reputation: 17,424

Post » Fri Mar 06, 2015 4:08 am

@Tekniko
it is ok, you do not have to help me. ;)

Which movement did you use, if you remember? Bullet?
Many projects with breakout style games made with C2, including the ones in tutorials and examples (and my own older projects on break out style games), have this problem with bouncing off in unpredicted way once in a while if they use bullet behavior plus collision with solids - Bounce off Object. (for example going into 45 degrees and then suddenly bounce off in like 23 degrees and not -45)

Boundary plugin is a nice way to keep the ball within the play area without writing too much events.

But I am open to debate of course, I want to perfect the ricochet process. :)

This is just experiment with goal to see if it can be polished into max.
B
58
S
18
G
13
Posts: 447
Reputation: 10,735

Post » Fri Mar 06, 2015 5:17 am

I can't open the capx now, but since you say breakout I'm guessing you'll only have unrotated rectangles that the ball bounces against.

One way to do it is to move the ball backwards when it collides with a block, which can be done with the push out of solid action of custom movement. Then you can use dom's idea to find what direction walls are.

Bouncing off horizontal and vertical walls is just a matter of reversing the y or x velocity of the object. You can also calculate the bounce angle if you know the angle of the wall hit but I don't recall the formula off hand.
B
88
S
30
G
89
Posts: 5,104
Reputation: 60,319

Post » Fri Mar 06, 2015 5:34 am

check out this tutorial, It might be helpful

https://www.youtube.com/watch?v=tYKDKwajXOY
should be about 3:00 min or a little more in when he sets up how it collides with the ball and paddle
B
29
S
6
G
1
Posts: 93
Reputation: 3,020

Post » Fri Mar 06, 2015 3:26 pm

@ZeroBelow I have that project, it was one of the first tutorials I followed. ;)

@R0J0hound I tried as you suggested, push out of solid action, and I thought it would be a good solution. But the ball will just pass through if I choose "opposite direction". When choosing "near" it will go "around" the block in funny way, so at least that one is working.

If you could figure out the formula I would be very happy.

To everyone, here I have made another project, but not in CAPX because of your not wanting to download plugin. @Tekniko

http://www.funnybunny.se/files/ballexamples/

Four examples of different types.
Look at how the classic bullet would go off in strange angles when sped up or after a while.
and the classic config of solid walls and bullet would escape at max speed (on my computer at least) but this problem won't happen with the Boundary plugin.

I hope you will understand what I mean with keeping proper angles AND minimizing risk of escapey ball.
I know thicker walls = better chance to keep in the ball.
B
58
S
18
G
13
Posts: 447
Reputation: 10,735

Next

Return to How do I....?

Who is online

Users browsing this forum: dzert14, JaisonAntoniazzi, Pulstar and 1 guest