1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 RTS unit position after movement

Discussion in 'Programming' started by Shavv, May 30, 2018.

Tags:
  1. Shavv

    Shavv Member

    Joined:
    Aug 3, 2016
    Posts:
    56
    Heey guys, i need some help. After i make my units order to move i want them to have a formation. But im having trouble creating a formation. I could make the formation with hand and assign each unit number to a position one by one, but having over 100 units would be a huge task.

    So i wanted to know if there is a math equation to this outcome i want to have.

    I also saw some other post with a similiar-ish problem but wasn't really helpfull.

    [​IMG]


    [​IMG]

    Code:
    if selected=true
    {
     if mouse_check_button_pressed(mb_right)
     {
      walkx=mouse_x
      walky=mouse_y
     }
    }
    
    if state=0
    {
     if distance_to_point(walkx,walky)>1
     {
      mp_potential_step_object(walkx,walky,movespeed,SOLID)
      if xprevious<x {image_xscale= 1}
      if xprevious>x {image_xscale=-1}
     }
    }
     
  2. Smiechu

    Smiechu Member

    Joined:
    Jul 14, 2017
    Posts:
    626
    When you make a selection, make one of the units a "leader". Leader will get a list of units within selection.
    Than, your orders are passed only to the leader, and the leader passes the order to all other units form the list with checking their relative position.
    Later in this approach you can define how the formatiom should behave, i.e. turn the formation in the direction of movement...
     
    Rob likes this.
  3. Shavv

    Shavv Member

    Joined:
    Aug 3, 2016
    Posts:
    56
    I tried something like that, but didnt seem to work for me (probably did it wrong hence why im here) because the position i got out of it made them make a diagnal line
     
  4. Morendral

    Morendral Member

    Joined:
    Jun 27, 2016
    Posts:
    386
    In that case you just need to change the code that assigned the relative positions. Post that code and we can try to help with it. I've done this exact thing myself before.
     
  5. Jdown79

    Jdown79 Member

    Joined:
    Aug 21, 2016
    Posts:
    69
    Isn't the issue here that all of your soldiers are trying to go into the space of one?
     
  6. Niels

    Niels Member

    Joined:
    Jun 22, 2016
    Posts:
    828
    Looks like every soldier is moving towards the same position..
    The target position should have a grid with the offset of every soldier.
    For example:

    XXX ====> XXX

    Instead of:

    XXX===> X
     
  7. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,464
    Two options:
    1: keep exact formation.
    When you give a movement order, find the average position of all selected units.
    Each unit then finds the offset from that center point. They will then navigate towards the target point, plus that offset.

    2: new formation
    When giving an order, make a list of all selected units. Then, use that list to give each unit a new position.
    Look at div and mod to go from the list index, to a position in a grid.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice