Weird problem with collision detection

0 favourites
  • 12 posts
From the Asset Store
Detects any kind of ad blocker. Very easy implementation into already existing projects
  • 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?

    <img src="https://dl.dropbox.com/u/97534866/enemy.jpg" border="0" />

  • 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.

  • 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

  • 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

  • thank you very much I will try that. But may I ask why my version does not work? Logically I think it should

  • 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 question

  • 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

    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.

  • > 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

    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.

    Ah you are right. So what would be the best solution for this?

  • 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 perfectly

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well I cant open it. It says it is made by newer version but I have the last one 1.3

  • scirra.com/construct2/releases

    download topmost - Construct 2 r105

  • Thank you so much podpathos. It works great.

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