Weird problem with collision detection

Get help using Construct 2

Post » Fri Oct 05, 2012 4:46 pm

Hello guys I am having weird problem with collision detection. I have two walls. one is on left side of the screen and is called "leftbounce" second on the right side of screen and is called"rightbounce".

Now what I have is that when some enemy hits the wall I change direction of enemy movement. So it basically looks like they bounce from the wall in opposite direction. However sometimes (not really often) collision just does not work and enemies continue moving im the same direction which means they go out of the screen. I dont get it. Does anyone know what could be wrong please?

elsewhere in the code I also have something like: every 5 seconds add 50 to current speed. So after a while enemies moves faster and faster. Could this be the cause?

Michal112012-10-05 16:50:49
B
8
S
2
Posts: 45
Reputation: 1,168

Post » Fri Oct 05, 2012 5:31 pm

The "Pick all" condition is unnecessary. The object is already picked from the collision condition. Unless you want to pick every instance of enemy1 when one of them hits a wall, which is what this is doing.

At really high speeds you can run into issues where between ticks the objects moves so far that it doesn't actually collide with the wall, hence it passes through. But that is really high speeds we're talking about.

Do your walls contain the "Solid" behaviour? If not, that's likely your problem.inkBot2012-10-05 17:33:51
B
73
S
20
G
10
Posts: 524
Reputation: 9,896

Post » Sat Oct 06, 2012 12:07 pm

Hi thank you for help, but it did not help. It almost seems like there is some bug. I made a small example which shows the problem. Just run it and wait few seconds. You will see what I mean. The faster speed is, then more evident is the problem. And if I give walls solid behaviour it makes it act even weirder. Thank you

https://dl.dropbox.com/u/97534866/problem.capxMichal112012-10-06 12:08:29
B
8
S
2
Posts: 45
Reputation: 1,168

Post » Sat Oct 06, 2012 5:03 pm

use overlaping at offset and it will work. I have set it to X:4 and X:-4 so that it works at high speed, but you can set it to2 or 1...

capx
B
12
S
2
G
2
Posts: 96
Reputation: 1,583

Post » Sat Oct 06, 2012 6:30 pm

thank you very much I will try that. But may I ask why my version does not work? Logically I think it shouldMichal112012-10-06 18:30:21
B
8
S
2
Posts: 45
Reputation: 1,168

Post » Sat Oct 06, 2012 9:04 pm

I can't figure out why, it seams that in same event C2 can't apply action to all instaces via pick all. But here is second soulution for your problem, this time with checking for collision http://db.tt/YhpwdOYM

edit: maybe Ashley can answer your questionpodpathos2012-10-06 21:13:05
B
12
S
2
G
2
Posts: 96
Reputation: 1,583

Post » Sat Oct 06, 2012 10:23 pm

[QUOTE=Michal11] Hi thank you for help, but it did not help. It almost seems like there is some bug. I made a small example which shows the problem. Just run it and wait few seconds. You will see what I mean. The faster speed is, then more evident is the problem. And if I give walls solid behaviour it makes it act even weirder. Thank you

https://dl.dropbox.com/u/97534866/problem.capx[/QUOTE]

The problem here is that event 3 and 4 trigger for each sprite3 that collides with the wall. So if 2 collide at the same time they get reversed twice and end up going the same way. At the start when they move to the right, the one on the top row hits the wall first and they all reverse. When they move to the left, both sprites on the left have the same x value so they both hit the wall at the same time and reverse twice - they carry on through the wall.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sun Oct 07, 2012 12:00 pm

[QUOTE=ramones] [QUOTE=Michal11] Hi thank you for help, but it did not help. It almost seems like there is some bug. I made a small example which shows the problem. Just run it and wait few seconds. You will see what I mean. The faster speed is, then more evident is the problem. And if I give walls solid behaviour it makes it act even weirder. Thank you

https://dl.dropbox.com/u/97534866/problem.capx[/QUOTE]

The problem here is that event 3 and 4 trigger for each sprite3 that collides with the wall. So if 2 collide at the same time they get reversed twice and end up going the same way. At the start when they move to the right, the one on the top row hits the wall first and they all reverse. When they move to the left, both sprites on the left have the same x value so they both hit the wall at the same time and reverse twice - they carry on through the wall.[/QUOTE]

Ah you are right. So what would be the best solution for this?
B
8
S
2
Posts: 45
Reputation: 1,168

Post » Sun Oct 07, 2012 12:43 pm

look at capx from my second post http://db.tt/YhpwdOYM - there you can use collision detection, sprite (on left/begining and right/end of group)are at same x position, and via 'global varariable' they move perfectlypodpathos2012-10-07 12:50:16
B
12
S
2
G
2
Posts: 96
Reputation: 1,583

Post » Sun Oct 07, 2012 8:53 pm

Well I cant open it. It says it is made by newer version but I have the last one 1.3
B
8
S
2
Posts: 45
Reputation: 1,168

Next

Return to How do I....?

Who is online

Users browsing this forum: BACLog and 20 guests