How to Set Multiple way points.

So in rts games, if you right click while selecting units, they will run to that location. This I can already do.

1 - But, if you shift+ right click, you can set multiple way points, meaning once that unit reaches the first way point ,they will then go to the next way point. Also, usually there is no Limit on how many way Points you can add using this method.

2 - you can have different groups having different way points at the same time. and you can also split a group that already has a few way points that they have not reached, and add more way points for 1/2 the group.

I was thinking it has something to do with arrays, but even if I knew how to use them properly which I dont, I cant see how they can meet all these conditions. and it doesn’t seem reasonable that every unit in an rts game can have a whole list for his own to save his way points? or does that sound reasonable? Imagine 100 units having their own list/array?

but lets assume every single unit does create his on list/array, what happens when I cancel those way points and start a new one? then what? as you can tell, I have no Idea how to get this part done.

and this is Just the Basics, in rts games, you can also assign multiple different task, such as “walking to location”, and then after that, Build something, and then after that, repair a building, and then after that walk to a different location, All by using the “shift” key. please educate me!!

Thanks in advance

I don’t think a List of 100 waypoints for 100 units is somehow excessive, they could be just Vector3 values (if it’s a 3D point) at bare minimum. Just store coordinates in order. But in real world you probably need some other data too.

And I would judge the reasonability (just like with content) by running tests and see if it goes ok, if there’s no excessive amount of memory wasted, don’t try to do premature optimization.

To add waypoints to your list, you could convert mouse clicks or touches to world coordinates and then add your point to a list. Each Unit should probably have a List, where it stores it’s waypoints.

// Declare a list in the Unit
List<Vector3> wayPoints = new List<Vector3>();

// To add to the list, you could have a method:
void AddWayPoint(Vector3 position)
{
   wayPoints.Add(position);
}

When you cancel the waypoints, you could just discard the List contents?

YourListName.Clear();

It might be a good idea to check Youtube etc. for tutorials/developers doing something similar on this topic to get ideas how to implement certain things.

1 Like

What you can do is have a List<> of waypoints, When you right click add your item to your list when your player reaches the destination remove it from list,
Now when you hold down shift keep adding they waypoints to your list and make the the player go to each one by one, when the player reaches every destination remove them from the list.

1 Like

And how to I add tasks that may have nothing to do with way points 1/ way through adding the way-point cycle. This is what made me think, that there must be another way.

So your suggesting, that 100-1000 units having their own dedicated list of way points inst excessive? consider that if all those units are selected at the same time, they will all be adding that way point to their own personal list.

I think you should build your prototype first and see how it runs. Then if you run into a brick wall, try something else? I think thinking this kind of what ifs doesn’t help. Your (and mine) time would be better used if you tried it out and see what problems (if any) emerge.

Of course you could try to pack your data to one list with identifiers to what Unit a waypoint belongs, but then when you need to iterate through that List, you do it every time for the whole list.

1 Like

your right, thx bro, ama give it a shot!

Thx bro, I made it work for now, but I had a few questions:

  1. is there a way to add Vectors to this List without creating your Method?
    for Example, this is how I use to add “Units to a List”
SelectionManager.ctrlGroup2.Add(myUnit);
  1. if I want to move the first Vector [0] on a list to the bottom, is there a way to do that? I already know a way to do that but I am not sure if there is a shorter method, My Method would be to add that same vector again to the list and then remove Vectro [0], which is a two step process, wondering if there another way.

  2. Can I add a vector to a list, but at position [1] or whatever position I want, as appose to the end of the list.

  3. Is it possible for me to add “functions / methods” to a list, such as “void AddWayPoint()”…

Thank you very much for your time, I am still a noob, and I would appreciate any answers, and I would further appreciate if you were to give examples because, I am still learning.