distance between characters

Started by , Mon 23/01/2006 08:03:23

Previous topic - Next topic

Martina

I'd like to make something like a fight in my game, but where the enemy and the player would be moving and they would be attacable from a specific (or smaller)distance between them (it would be with a longsword), but I don't know how to define the distance. Please help.

Gilbert

Simplest way is to calculate it like this (don't need to square root it unless you really need that):

xdiff = cEgo.x - cEnemy.x;
ydiff = cEgo.y - cEnemy.y;

dif = xdiff*xdiff + ydiff*ydiff;

SMF spam blocked by CleanTalk