Jump to content


Photo

Distance Forumulæ


  • Please log in to reply
6 replies to this topic

#1 ngc0202

ngc0202

    GMC Member

  • New Member
  • 190 posts

Posted 28 February 2010 - 04:14 AM

I am using a distance formulæ:
xx = NPC.x-x;
yy = NPC.y-y;
global.NPCdist = sqrt(xx*xx+yy*yy);
...which checks the distance between the main character and an NPC. When I put in a second instance of the same NPC, it only works for the first of the instances place (the one with the lower ID). Is there any way to make this code work with multiple NPC?

Edited by ngc0202, 28 February 2010 - 06:36 AM.

  • 0

#2 EchoJerichoX

EchoJerichoX

    www.MetroidCoven.com

  • GMC Member
  • 501 posts
  • Version:GM8.1

Posted 28 February 2010 - 04:20 AM

If you are trying to get the nearest NPC's x and y, try using instance_nearest...

xx = instance_nearest(x,y,NPC).x;
etc...
  • 0

#3 PlasticineGuy

PlasticineGuy

    GMC Member

  • New Member
  • 2384 posts

Posted 28 February 2010 - 04:27 AM

"formulae" is the plural.
  • 0

#4 EchoJerichoX

EchoJerichoX

    www.MetroidCoven.com

  • GMC Member
  • 501 posts
  • Version:GM8.1

Posted 28 February 2010 - 04:38 AM

"formulae" is the plural.


We're aware. Thanks.
  • 0

#5 ngc0202

ngc0202

    GMC Member

  • New Member
  • 190 posts

Posted 28 February 2010 - 04:42 AM

"formulae" is the plural.

I didnt say formulae, I said formulæ. And thank you for the code Echo, it worked.
  • 0

#6 EchoJerichoX

EchoJerichoX

    www.MetroidCoven.com

  • GMC Member
  • 501 posts
  • Version:GM8.1

Posted 28 February 2010 - 04:43 AM

You are very welcome :(.
  • 0

#7 ND4SPD

ND4SPD

    GMC Member

  • GMC Member
  • 2175 posts

Posted 28 February 2010 - 07:13 AM

Would it not be better to do this?
ii = instance_nearest(x,y,NPC);
global.NPCdist = point_distance(x,y,ii.x,ii.y);

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users