How do I math? ^^

0 favourites
  • 4 posts
From the Asset Store
Aliens are invading our planet! Solve the math question, and attack the alien with your laser. Covers addition, subtract
  • Hi,

    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

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

    [attachment=0:1xmicg0s][/attachment:1xmicg0s]

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So it's like a triangle formation. If you disregard centering you can visualize the placement of the nth follower with:

     1  3  6 10 15
     2  5  9 14
     4  8 13
     7 12
    11[/code:12i2572a]
    
    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:12i2572a]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)[/code:12i2572a]
    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:
    [url=https://dl.dropboxusercontent.com/u/5426011/examples22/squad.capx]https://dl.dropboxusercontent.com/u/542 ... squad.capx[/url] 
    
    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.
  • 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!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)