PDA

View Full Version : [AS3] Formula for collision?


SaladBowler
01-07-2011, 01:44 AM
Still working on an online zombie game, ran into a possible problem of NPC zombies running through walls.

So i have a map with bounderies, that the local user will stop at wall fine because flash just tells it can't go through there. the problem is the zombie npcs are controlled through a cron tab PHP script, which gets the map Bounderies and randommizies its next location to move to. Now your up to speed...

The zombies will not go to locations that the boundaries are set, however they will go through them to reach there destination, so how can i make a formula that will pre-calculate that the zombie will hit the wall on its way to its destination, so the php script can know ahead of time that it should send the zombie else where?

92Garfield
01-07-2011, 01:58 AM
var futureCollide = false;

for (var i= 0; i< 1000; i++) {
doZombieStep(copyOfActualZombie);
futureCollide = checkCollision(copyOfActualZombie);
}

if (futureCollide ) {
//the zombie will run into a wall...
}

SaladBowler
01-07-2011, 02:04 AM
var futureCollide = false;

for (var i= 0; i< 1000; i++) {
doZombieStep(copyOfActualZombie);
futureCollide = checkCollision(copyOfActualZombie);
}

if (futureCollide ) {
//the zombie will run into a wall...
}

Thanks! But I forgot to mention that this collision detection MUST be done in PHP.

Crontab:
Map Bounderies(MySql) -> Check Collision(PHP) -> updateZombies newX & newY(Mysql);


Client:
Zombie Position Updater Loop(Flash)-> get position(Mysql/PHP)

92Garfield
01-07-2011, 01:04 PM
well, it's just the principle, no realy code anyway.

Build that in PHP then:rolleyes:

Let me have a try in PHP

$futureCollide = false;
for ($i= 0; $i< 1000; $i++) {
doZombieStep($copyOfActualZombie);
$futureCollide = checkCollision($copyOfActualZombie);
}
if ($futureCollide ) {
//the zombie will run into a wall...
echo "OMG A WALL!!!11";
}
something like that right?:p

SaladBowler
01-07-2011, 02:09 PM
Right, I appreciate your help except your method was my first attempt..and of course it works but this game is already CPU/Network intesntive and i think it would be ineffeicent for flash to wait on php to finish a loop which CPU cycles could be saved if i get a math formula in here

SaladBowler
01-08-2011, 01:37 AM
Well it seemed to difficult, so i just made the crontab, += X & Y values every refresh and if it hit the wall it would go in a diff direction