lol I'm home sick with a 103 degree fever... I took motrin so its ok right now...
lol I'm home sick with a 103 degree fever... I took motrin so its ok right now...
Hi!
I've been working a long time on this problem without finding a perfect solution.
Here's an example which works until there are more than 2 simultaneous overlappings ('cause it works with 2 counters = 2 objects)...
I wish it could help you!
http://www.yousendit.com/download/cTonTt9np3l5TA%3D%3D
If somebody could improve this method, i'm interested!!
PS : As i'm french the comments in the .mfa are quickly translated so : sorry for my english!! [grin]
BenJ




Okay well I've been using a method for detecing similar objects.
You will need one detector object (possibly more depending on movement) and then you have your two or more duplicates. Here is an example of how you apply them:
To simplify the example let's say that the zombies only move left at 1 pixel at a time. The detector is for the zombies left side. We only need 1 detector even though we have multiple zombies, because we will use loops.
Always run a loop for the number of zombies that there are
On loop "zombie"
and zombie Id = loopindex("zombie")
+ Set the detector's x to the zombie's current x position - 1
+ set the detecotr's y position to the zombie's Y
On Loop "zombie"
and zombie Id = loopindex("zombie")
and detector is not overlapping a backdrop
and detector is not overlapping a zombie
+ Zombie.x = Zombie.x - 1
//Here is the code that will be able to find when one zombie overlaps the other, and pick the rightmost zombie. Note how I have not used 'and zombie Id = loopindex("zombie")'
On Loop "zombie"
and detector is overlapping a zombie
+ Set Detector's Flag 0 to on
On Loop "zombie"
and detector flag 0 is on
+ Detector.x = Detector.x + 4
// The detector now moves 4 pixels to the right, so it will be overlapping the zombie which is trying to move right.
On Loop "zombie"
and detector is overlapping a zombie
and detector flag 0 is on
+ (Do something here, stop the zombie if you want)
+ Detector.x = Detector.x - 4
+ Detector.flag 0 = off
That's the end of the code. So basically what happens is you run a loop through all the zombies, putting the detector in front of them. As soon as the detector overlaps a zombie, you know that a collision between two zombies has occured. In this instance you move the detector 4 pixels to the right, so now it will be overlapping the zombie which did the colliding. Since the detector is only overlapping one object we are able to isolate it and apply actions to it.
I can make a quick example if you want me to.
If you a using a pathfinding extension then whilst looping the zombies put the tile that the current zombie is walking to as filled and the one it is on as empty.
This will mean that the zombies can't walk through the solid tiles and so in turn they can't walk on each other
wow nice code ninja... btw anyone else here get influenza? I was the first patient this year that got it in my area... Stupid virus lasts for 5 days!
I've got a better idea for the detector system. It is just like ninja put. It will be a rectangle roughly that size of the zombie (when the zombie is not rotated), and then it will put the detector on a zombie, and detect if there is a zombie overlapping it that is not the zombie it is supposed to be on, then, if there is an overlap (and not overlapping a backdrop, it will get the angle between the zombie and the detector, then it will move the zombie away about 2 pixels. If that movement puts the zombie into a backdrop, it moves it back to its previous location, and moves on to the next zombie in the loop.
If comparing angles is too slow, I'll just compare along each axis.
I'm not using a pathfinding extension, I'm using a cheap method that detects if the zombie is on a collision course with an obstacle, and rotates it away from the obstacle. It works surprisingly well.
Yesssss!!!!! I just tried my method that I told about above, and it worked!!!!!
nice!
Could you post an example to show us how exactly you do that???
Thanks
Ben
Glad you could fix it. Like Phenix said... Could you post an example of how you did it?
Share your method with your friends!Barbie Girl(man I hate that commercial...)