Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Mon 23/01/2006 08:03:23

Title: distance between characters
Post by: on Mon 23/01/2006 08:03:23
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.
Title: Re: distance between characters
Post by: Gilbert on Mon 23/01/2006 08:54:18
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;