How to use setFollowTarget()?


I want to let my bot follow player but it just nothing happend.


How to fix it?


So this is tricky to explain, as I only really know a part of it:

Follow, as a command, is handled via the gameSpace portion of the client. As I understand it, this is a state that lives only on the frontend, and is not accessible via the Websocket. If you want to tinker around with it, use the console, and pull up gameSpace.

The Websocket call game.setFollowTarget appears to either fail to do its intended job (ie setting gameSpace.setFollowId) or it and the event playerSetsFollowId are intended to allow API scripts to see when someone has set a follow target, and change it. This could be useful in cases when following would allow users into a secret area, or when a mini-game might break if follow is allowed (think Gather tweeted about Hip-to-be-Square and follow being cheating).

Either way, there currently does not appear to be a good player.follow style command for the Websocket. Best you can do is use some of the pathfinding libraries out there, and use that to inform game.move actions. I know A-Star is a popular algorithm, but I am sure there are others.

EDIT: On additional investigation, neither call appears to do anything. The event “playerRequestsToLead” does fire, but the event “playerSetsFollowId” does not, either when following directly, or accepting a lead. I can only assume this was an incomplete project, or was broken at some point.

1 Like

Thank for your explain @Bill_Uncork-It , you help me so many times.

I see, I will try some pathfinding algorithm for now,and wait them done or fix the setFollowTarget haha.

thanks Bill :slight_smile:

I can confirm that when you follow someone in the Gather app, it’s all done client-side, outside of the server and websocket api. So writing your own search is the right option, here

1 Like

Hello, I have another question now.
If I need to write my search, then I need to know where are “impassable”.
I read the websocket API documentaion, but look likes no function can do this.
Is that mean I need to handmake something like CSV file to keep the “impassable” position?

game.completeMaps[/*YOUR MAP NAME HERE*/].collisions will return a 2-D array of booleans, with each element representing if a tile is impassible or not, as a boolean.

Depending on the format the search function is using, you may need to transform this information. But that value represents, iirc, what the move commands check against to make sure players cannot phase through walls.

1 Like

Thank you again!

I thought it would be get by a function haha.