Page 1 of 1

Moving to the nearest candy

PostPosted: Sat Dec 09, 2006 7:30 am
by Troodon
Hi,
When I make moveto candy (an actor), my main actor goes always towards the latest (or newest) candy actor. Is it possibly to change it so that it goes always to the nearest?

Another question:
How is the distance working with if function? I want a reaction when the distance is smaller than 50 pixels.

PostPosted: Sun Dec 10, 2006 4:17 pm
by Troodon
Anyone?

Re: Moving to the nearest candy

PostPosted: Sun Dec 10, 2006 6:26 pm
by makslane
tekdino wrote:How is the distance working with if function? I want a reaction when the distance is smaller than 50 pixels.


Code: Select all
if(distance(x, y, other.x,  other.y) < 50)
{
  //your action here
}

PostPosted: Mon Dec 11, 2006 7:14 pm
by Troodon
Thanks Maks! :D
Now I'm trying to make: if actor nearer than 50 pixels, move to another direction. However this is little hard.

I tried to use the code above you gave me and this code that I had some days ago together but I couldn't succeed. How should I make it work?

The code I had from this forum:
Code: Select all
angle=direction(mainactor.x, mainactor.y, monster.x, monster.y); +180;
directional_velocity=2;