It begins with finding a target..

smurftedsmurfted Member, PRO Posts: 570

How can i make an actor look at a series of actors and have it decide to go to the closest one?

Comments

  • zweg25zweg25 Member Posts: 738

    If you have the other actors X and Y positions (stored in a game attribute or table) you could loop through them and see which distance is the smallest (remembering the distance formula is sqrt[(self.x-actor.x)^2+(self.y-actor.y)^2].

    There may also be something better with path finding, but I have never used it

  • smurftedsmurfted Member, PRO Posts: 570

    Epic, i will see if i can get that up and running..

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    The magnitude function is a little simpler than the distance formula.

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

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    The Magnitude Function works well, here is a tutorial if you want to check it out:

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    Here another approach using a 'detector' - file attached.

    Drag the little purple dots around, then click on the central player to detect and move to the nearest dot.

    It would probably needs lots of refinement, but should give you the basic idea.

  • smurftedsmurfted Member, PRO Posts: 570

    Yet again some epic stuff in here lads, i'll have to try a few versions for sure as i want lots of little characters looking for each other.

    So i'll have to try and work out which is the fastest way to get this looping..

Sign In or Register to comment.