Issue with Formations

Get help using Construct 2

Post » Thu Aug 08, 2013 9:01 am

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.

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

Edit: I'm running this in Chrome.SAAj2013-08-08 09:03:24
B
4
S
1
G
2
Posts: 39
Reputation: 1,028

Post » Thu Aug 08, 2013 11:34 am

Add 'for each direction' below stop=0 condition. You should check some tutorials about picking to understand the need for 'for each' there. :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,242

Post » Mon Aug 12, 2013 12:50 pm

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

https://www.dropbox.com/s/dkxmcom1qnmbgxu/M%26B%20Commander.capx
B
4
S
1
G
2
Posts: 39
Reputation: 1,028

Post » Mon Aug 19, 2013 8:02 am

bump :C
B
4
S
1
G
2
Posts: 39
Reputation: 1,028

Post » Mon Aug 19, 2013 8:15 am

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.
B
215
S
57
G
32
Posts: 900
Reputation: 38,779

Post » Mon Aug 19, 2013 8:24 am

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
B
24
S
8
G
7
Posts: 756
Reputation: 7,242

Post » Tue Aug 20, 2013 12:56 pm

[QUOTE=vee41] 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[/QUOTE]

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?
B
4
S
1
G
2
Posts: 39
Reputation: 1,028

Post » Tue Aug 20, 2013 1:55 pm

[QUOTE=SAAj]

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?[/QUOTE]

Added it to the example. :)

Formations
B
24
S
8
G
7
Posts: 756
Reputation: 7,242

Post » Tue Aug 20, 2013 2:21 pm

[QUOTE=vee41] [QUOTE=SAAj]

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?[/QUOTE]

Added it to the example. :)

Formations[/QUOTE]

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.
B
4
S
1
G
2
Posts: 39
Reputation: 1,028


Return to How do I....?

Who is online

Users browsing this forum: RetroSpock, senna68, WhosWho and 9 guests