• Create Account

### #Actualj-locke

Posted 01 August 2012 - 04:55 PM

The problem is in the loop where you check for collision.

If you put a breakpoint on the first line inside that loop, you can step through and see exactly what's going on there.

An example scenario is if you have your player standing on the first entity of the list:
-- first iteration --
if (player intersects with entity[0]) is true, so set terrain collision to true
if (player DOES NOT intersect with entity[0]) is false
-- second iteration --
if (player intersects with entity[1]) is false
if (player DOES NOT intersect with entity[1]) is true, so set terrain collision to false

So the way your code currently checks for collision, it's really just telling you if the last entity added is colliding with the player.

I'm not sure what you're going to do with that collision information, so I can't recommend a good way to solve your problem.

If this is the kind of game where colliding with any terrain means you die, a solution could be to add a break; statement inside the intersection code block. That way if somebody collides with any of the entities, it will set terrainCollision to true and then break out of the for each loop. So you could check that variable later and see if the player should die.

If you need more information like which entity it is colliding with, you may need an additional variable to put some meaningful information into.

### #1j-locke

Posted 01 August 2012 - 04:53 PM

The problem is in the loop where you check for collision.

If you put a breakpoint on the first line inside that loop, you can step through and see exactly what's going on there.

An example scenario is if you have you player standing on the first entity of the list:
-- first iteration --
if (player intersects with entity[0]) is true, so set terrain collision to true
if (player DOES NOT intersect with entity[0]) is false
-- second iteration --
if (player intersects with entity[1]) is false
if (player DOES NOT intersect with entity[1]) is true, so set terrain collision to false

So the way your code currently checks for collision, it's really just telling you if the last entity added is colliding with the player.

I'm not sure what you're going to do with that collision information, so I can't recommend a good way to solve your problem.

If this is the kind of game where colliding with any terrain means you die, a solution could be to add a break; statement inside the intersection code block. That way if somebody collides with any of the entities, it will set terrainCollision to true and then break out of the for each loop. So you could check that variable later and see if the player should die.

If you need more information like which entity it is colliding with, you may need an additional variable to put some meaningful information into.

PARTNERS