Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   Collision Detection within a list of objects (http://www.alice.org/community/showthread.php?t=6319)

kompsci 04-13-2011 08:34 PM

Collision Detection within a list of objects
 
hey, im making a fps where there are a bunch of zombies running towards the player(total of 16 zombies at the moment) and when you shoot them they disappear.
I created a list of zombie objects and got them all moving using the list and everything was working fine until i came to the problem of checking collision with the bullet that is fired from the gun at the zombie.
Previously i had checked for collision using each individual zombie object but with so many zombies i tried to implement a method that would loop through the list of zombies and check to see if the sphere had collided with said zombie.
It worked great in my head but not in the actual implementation. Below is my code in pseudo code-like form

[CODE]infinite loop{

for each zombie in zombie list{

if(zombieCounter > numberOfZOmbies) // this resets the loopCount

zombieCounter == 0;

}

if(bullet is withing 5 meters of itemFromZombieList){

destroy zombie or whatever

}

increment loopCount by 1

}






[/CODE]


i think my problem is that i dont know how to refer to a specific index of my list. i want to be able to say if spher is within threshold of zombie at index loopCount but i can only seem to be able to say if its within ANY zombie object in the list. i hope my question is clear enough.

i got the zombies to disappear when the bullet hits ANY zombie and the zombies disappear in the order they appear in teh list. i cannot figure this out for the life of me

TheWhiteGuy 04-14-2011 11:34 AM

ok if u are using Alice 2.0 then what should work if u go and click on events and click <create new event> then do <when the mouse is clicked on something> then just change <something> to one of the zombies then create the method of it dieing/disappearing. That should work.

kompsci 04-14-2011 04:22 PM

ok ill try that out


All times are GMT -5. The time now is 08:50 AM.

Copyright ©2021, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.