0 Favourites

Issue with Formations

  • 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.

  • Add 'for each direction' below stop=0 condition. You should check some tutorials about picking to understand the need for 'for each' there. :)

  • vee41

    Thank you for the reply! It fixed the issue of Soldiers jumping from one Direction to another, but there is still the issue of Directions coming to a stop when their Formation overlaps another Direction (if you click and drag a Formation onto a Direction other than the one in its container, the Direction stops rotating and moving until the Formation is no longer overlapping another Direction).

    I checked the page on picking for Construct 2 and it didn't seem to cover what I should do here. I think I need to use 'for each Formation', but since I don't have Formation selected as an object in my conditions (it is instead selected as a position), it's not registering. Or I could be completely wrong.

    What should I do to prevent a Direction from stopping when its Formation overlaps another Direction? I've included the updated .capx below.

    dropbox.com/s/dkxmcom1qnmbgxu/M%26B%20Commander.capx

  • bump :C

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Have you looked at the "Real Time Strategy" example? maybe it has something that could help?

    Start construct, hit new, and type "Real" it should be the only one.

    Look under the Player Unit control section.

  • I removed the whole on overlap, as it doesn't differentiate betwee the units own formation and other ones. Also got rid of the whole angle thing, as there really is no point in that :)

    Fixed formations

  • I removed the whole on overlap, as it doesn't differentiate betwee the units own formation and other ones. Also got rid of the whole angle thing, as there really is no point in that :)

    Fixed formations

    That's the problem, I need the soldier to always face the same direction as the Commander; if a shieldwall is not facing forward, it's useless as a shieldwall. If not for that, it would be easy and I wouldn't need the Direction at all.

    If I can't get each Soldier to follow its Direction while each Direction follows its Formation, I'd have to find a way to make the Soldier move in the direction of its Formation while still facing forward. Is it possible to translate an object in a direction without changing its angle?

  • That's the problem, I need the soldier to always face the same direction as the Commander; if a shieldwall is not facing forward, it's useless as a shieldwall. If not for that, it would be easy and I wouldn't need the Direction at all.

    If I can't get each Soldier to follow its Direction while each Direction follows its Formation, I'd have to find a way to make the Soldier move in the direction of its Formation while still facing forward. Is it possible to translate an object in a direction without changing its angle?

    Added it to the example. :)

    Formations

  • >

    >

    > That's the problem, I need the soldier to always face the same direction as the Commander; if a shieldwall is not facing forward, it's useless as a shieldwall. If not for that, it would be easy and I wouldn't need the Direction at all.

    >

    > If I can't get each Soldier to follow its Direction while each Direction follows its Formation, I'd have to find a way to make the Soldier move in the direction of its Formation while still facing forward. Is it possible to translate an object in a direction without changing its angle?

    Added it to the example. :)

    Formations

    Thank you, that solved the problem! I just assumed an object couldn't move in a direction it wasn't facing. That's what I get for not paying attention in math class.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
300 118,413
blackhornet's avatar
blackhornet
Unread hot topic
0 Favourites
Spam issue
201 16,826
Tom's avatar
Tom Construct Team Founder
Unread hot topic
157 12,688
megatronx's avatar
megatronx