Closest distance at which a missile passes by your hero

Nah, it’s (mainly) for Sarven treasure 5, in order to dodge razor disks from HeadHunters.

My apocalypse code is more a swisscheese problem, where I define holes where I should not be at a given time. I get positions of the explosions with missile.targetPos (X,Y) and the timing is 3.6sec after a missile appears (T). So I find the safest path through this cheese, by checking the space-time distance from the explosion. Here is the idea :

// When a missile appears, I record the 3 parameters of the shell in an array.
X = missile.targetPos.x ;
Y = missile.targetPos.y ; // in meters.
T = this.now() + 3.6 ; // in seconds

In order to know if a position (x,y) is safe at a given time t, you can check if this position (x,y,t) is far enough from the explosion.

dX = X - x ;
dY = Y - y ;
dT = T - t ;
v = this.velocity

distanceFromExplosion = Math.sqrt( dX*dX + dY*dY + v*v*dT*dT ) ;

If distanceFromExplosion > explosionRadius (which is 10, but using 11 or 12 is safer), then the position (x,y,t) is safe.

So when I detect the position of my hero isn’t safe anymore, I compute several path around me (in a star pattern) to check that every steps (x,y) on my way to a safe position are safe (t is a future time. It is computed via t = distance / velocity). If I find one fully safe path, I do take this path. Rince and repeat.

Sometimes, there isn’t a path and the hero dies horribly. But that’s part of the fun :smile:

PM me if you want more info on Apocalypse.

4 Likes