several numbers how to find the biggest one?

ownage11ownage11 Member Posts: 39
edited April 2012 in Working with GS (Mac)
I have an enemy, and I want it to move towards the player that is closest to it. I know how to do distance: magnitude( self.Position.X - game.player x , self.Position.Y - game.player y )


If i get like 5 numbers for 5 different distances how can I ask the system to figure out which number is smallest?

If i can do that then i can make the enemy go towards the player closest to it

Best Answer

  • tatiangtatiang Posts: 11,949
    Accepted Answer
    Another way is to change 5 attributes to each of your distances, game.distance1, game.distance2, etc. Then, do change attribute game.shortestDistance to min(game.distance1,min(game.distance2,min(game.distance3,min(game.distance4,game.distance5)))). Then have a rule that says When game.shortestDistance=game.distance1 --> attack enemy1; Otherwise When game.shortestDistance=game.distance2 --> attack enemy2, etc.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Answers

  • ownage11ownage11 Member Posts: 39
    It doesnt suck your the best tshirt booth thanks!!!
Sign In or Register to comment.