Moving to the nearest candy

Talk about making games.

Moving to the nearest candy

Postby Troodon » Sat Dec 09, 2006 7:30 am

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.
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Postby Troodon » Sun Dec 10, 2006 4:17 pm

Anyone?
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Re: Moving to the nearest candy

Postby makslane » Sun Dec 10, 2006 6:26 pm

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
}
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Troodon » Mon Dec 11, 2006 7:14 pm

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;
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest