Computer Science Canada

collision detection problem help!

Author:  staticlike [ Fri Apr 29, 2005 12:07 pm ]
Post subject:  collision detection problem help!

I'm having a tad bit of trouble with my collision detection on the game that i am creating. the only thing is, i don't understand why it is giving me trouble. here's my collision detection code:
code:
if walls (mx, my) = 1 then
            if rockettype = 1 then
                walls (mx, my) := 0
            elsif rockettype = 2 then
                for i : -1 .. 1
                    for o : -1 .. 1
                        walls (mx + i, my + o) := 0
                    end for
                end for
            elsif rockettype = 3 then
                for i : -2 .. 2
                    for o : -2 .. 2
                        walls (mx + i, my + o) := 0
                    end for
                end for
            end if
            launchm := false
            mx := -5
            my := -5
        end if


mx and my are the missile's coordinates, walls is a 2d array of int, a 1 signifies a wall, launchm is the check that a there is a launched missile, rockettype is the kind of rocket the player is using.

The problem is when the player shoots the rocket right next to a wall. it will destroy the wall and keep going, as if the wall wasn't there, and get destroyed when it hits the next wall. Any idea on why it does this?

Author:  Delos [ Fri Apr 29, 2005 8:14 pm ]
Post subject: 

I don't see an incorporation of the launchm boolean anywhere. You might want to enclose your code with:

code:

if launchm then
%...
end if

Author:  staticlike [ Mon May 02, 2005 11:46 am ]
Post subject: 

It already is enclosed inside of it, alongside the moving of it, so it can immediately destroy the wall if it moves into it.

oh yea, i found out the problem, though i don't remember what it was because i'm usually quite forgetful, plus it's been a few days after i fixed it. Razz


: