I'm kind of surprised there aren't more topics about this; my search mostly turned up stuff that was outdated/from Classic.
I'm making a game in which you control a Commander using WASD and your Soldiers follow you in formation. You can adjust their formation using drag-and-drop. I went about this as follows:
Each Soldier is comprised of 3 objects: Formation, Direction, and Soldier. Direction and Soldier are in Formation's container.
Formation: this is the drag-and-drop object that pins to the Commander and tells the Soldier where it should ideally be at all times.
Direction: this is the 'motor' that always faces the Formation and moves toward it if they are not already overlapping.
Soldier: this is the main sprite; it always sets its position to its Direction and its angle to the Commander, so that it faces outward no matter which way it's moving.
The problem I'm having is that Direction and Soldier are not sticking with their Formation; they behave strangely when interacting with other Directions and Formations, even if they're not part of that container.
I know there are ways to make them ignore all such objects except the ones they spawned with, but the method I used in Classic isn't working here for some reason (I had a private variable on all 3 objects that was set to Formation.Count when the objects spawned, and all commands involving movement and positioning applied only to objects that shared this private variable).
Here is the .capx as I have it so far. As soon as Directions/Soldiers start overlapping or moving past each other, everything goes crazy.
dropbox.com/s/dkxmcom1qnmbgxu/M%26B%20Commander.capx
Edit: I'm running this in Chrome.