Move to closest actor

Luke20wLuke20w Member, PRO Posts: 50

I am trying to make a Clash of Clans battle simulator and I need to make troops move to the closest actor with a tag defense, storage, any, etc. I've tried having an actor calculate the distance from every actor but that didn't work. Please help.

Comments

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    You're going to have to use the magnitude function to determine which actor is closest. At that point, it's just a matter of sending the X and Y positions of that actor to the movement actor. You can then plug those positions into an interpolate behavior, move behavior, or however you're moving your actor.

  • Luke20wLuke20w Member, PRO Posts: 50

    Ok thanks a lot @Braydon_SFX

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

    Here's a demo made with Mac Creator:

    http://forums.gamesalad.com/discussion/comment/520926/#Comment_520926

    Keep in mind that depending on your game setup, you might have to constrain the table cells to the enemy positions by using a Timer. This can have a pretty negative effect on app performance.

    Also, the Tech Support subforum is for technical issues with using Creator, not for coding questions like this. Are you using a Mac or PC? I can move this to the relevant subforum for you.

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    @tatiang said:
    Here's a demo made with Mac Creator:

    Yep. Very nice!

Sign In or Register to comment.