Move To Nearest Actor
Hello Guys, how are you?
Lets Say I have ONE actor A, and a Lot of actors B
How Can I make an Actor A Move To the Nearest Actor B?
Of Course I need To measure the Distance of Actor A and B.
And Actor A just need to move to the Nearest B. But How Can I compare all the data of the Actors B Distance to A to see who is the closest one to A?
Cheers.
Lets Say I have ONE actor A, and a Lot of actors B
How Can I make an Actor A Move To the Nearest Actor B?
Of Course I need To measure the Distance of Actor A and B.
And Actor A just need to move to the Nearest B. But How Can I compare all the data of the Actors B Distance to A to see who is the closest one to A?
Cheers.
Best Answer
-
lukey5227 Posts: 111
What if you have these:
Global attributes:
Total
Count
X Position
Y Position
Basically, Actor B has an attribute that is called id. What it does it change total to Total + 1 so now it counts up how many there are and gives each one an id.
Count equals 1. In Actor B, if Count = id
THEN
change Game.X Position to Self.Position X
change Game.Y Position to Self.Position Y
Actor A
New attribute: Self.count = 0
New attribute: Self.Distance = 10000000
If Game.Count ≠ Self.Count
THEN
change Self.Count to Self.Count + 1
----If Distance Equation Here > Self.Distance
----THEN
----change Self.Distance to Distance Equation Here
----change Game.Count to Game.Count + 1
----OTHERWISE
----change Game.Count to Game.Count + 1
OTHERWISE
change Game.Count to Game.Count + 1
DISTANCE EQUATION: (actor a position x - actor b position x)^2 + (actor a position y - actor b position y)^2 = (Distance Equation)^2
So this doesn't exactly give you the distance, just the distance squared. I think you can figure out the rest.
P.S. Just incase you didn't get it, its a^2 + b^2 = c^2...
Hope I could help!
Answers