Move to closest actor
Luke20w
Member, PRO Posts: 50
in Tech Support
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
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.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
Ok thanks a lot @Braydon_SFX
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.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Yep. Very nice!
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx