How do I math? ^^

Get help using Construct 2

Post » Sat May 10, 2014 3:14 pm

this one's a bit ambitious and I'm not asking for anyone to take me all the way, but I'd be thankful for any pointer that is more than a wiki link :roll: :oops:

So I want a squad to take on a formation around a leader.
Problem 1: I want the formation to rotate along the rotation of the leader
Problem 2: I want the formation to scale per number of units (see schematic)

(I'm only concerned with generating the positions, movement to these positions is solved with C2's pathfinding)

Green be the leader, blue be the squad units. Squad can vary in size (number of units).
You do not have the required permissions to view the files attached to this post.
Last edited by facecrime on Sat May 10, 2014 3:53 pm, edited 1 time in total.
Posts: 272
Reputation: 2,363

Post » Sat May 10, 2014 3:47 pm

I would say that first you need to know how many airship the leader is currently leading (and also which one are which)

Then there is ways to calculate the X and Y of the point you want to move towards:

The easiest: the positions are image points of the leader, no calculation needed, just to move towards the concerned imagepoint

Alternative: I think it would involve using the distance and angle wanted relative to the leader, and use it but I am not sure how for now mathematic wise yet.
Game design is all about decomposing the core of your game so it becomes simple instructions.
Posts: 2,123
Reputation: 17,200

Post » Sat May 10, 2014 7:22 pm

So it's like a triangle formation. If you disregard centering you can visualize the placement of the nth follower with:
Code: Select all
 1  3  6 10 15
 2  5  9 14
 4  8 13
 7 12

I don't see any good patterns that we can make a formula with but I can see a pattern with the follower number and it's column:
Code: Select all
num:  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
col: (1)(1  2)(1  2  3)(1  2  3  4)(1  2  3  4  5)

So we can do it with a loop:

number n=1
number column=1
for each follower
--- follower: set col to column
--- add 1 to column
------- if column > n
---------- add 1 to n
---------- set column to 1

So with that you can set the followers x position with leader.x + 64*follower.col.

Then if you loop through each column of followers you can set the y position and even center them vertically. See example for detail: ... squad.capx

The simplest way to position relative to the leaders angle is to use "move at angle" instead of set x and y. Again see example for detail.
Posts: 5,555
Reputation: 85,323

Post » Sun May 11, 2014 12:06 pm

R0J0hound that's amazing, thanks a lot! and way more than I was hoping to find.
It behaves exactly like I need it to and is a really elegant solution at that.

I do get how you position them according to their slot in the column and I didn't know about 'move at angle' which is pretty sweet.

I'm still struggling to wrap my head around how you determine and assign the columns though. maybe you have a(nother) second to help me understand:
what does which loop do?
you're giving each follower its column, depending on whether its count is higher than the current column?
and you count the columns in n? but you're rewriting it in the second loop, no?

anyway, thanks for your time and for providing a full solution, very much appreciated!
Posts: 272
Reputation: 2,363

Return to How do I....?

Who is online

Users browsing this forum: ultrafop and 6 guests