Move To Nearest Actor

MagoNicolasMagoNicolas Member, PRO Posts: 2,090
edited May 2012 in Working with GS (Mac)
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.

Best Answer

  • lukey5227lukey5227 Posts: 111
    edited May 2012 Accepted Answer
    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.CountSelf.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

  • MarkOnTheIronMarkOnTheIron Member Posts: 1,447
    Have you tried the magnitude demo by FMG? I think it had a system similar to the one you want to make.

  • MagoNicolasMagoNicolas Member, PRO Posts: 2,090
    For that to Work, I need to have Attributes for Each Actor, and I want it to be made Automatically, based on how many Actors B I have. I know a Method That I can do with Tables, but I want to se if there is an easier method. Thanks Anyways MArk.
Sign In or Register to comment.