Hi all I have a few basic questions that I’m hoping can be answered for me.
If I have multiple objects selected that I am moving (such as in an RTS for example) and I select them all to move to the same point they (naturally) all fight over trying to get to that spot to reach the end of their path and won’t sit still. Is there a way to prevent this? My thought process was to set the location of the objects to be unable to be traversed however this would mean regenerating the graph too often and cause lag. Is there an option (in either the free or pro versions that can prevent this). Similarly would the object avoidance prevent then objects from running through each other as they do now when moving them to the same location? Or will that also cause problems at the end of path whereby they try get there but bounce around because of avoidance?
You could try having them go into a formation by creating formation points.
using UnityEngine;
using System.Collections;
public class FormationObject : MonoBehaviour {
public Transform[] formationPointArray;
public int[] squadMembers;
// Use this for initialization
void Awake () {
//create squad formation points
formationPointArray = new Transform[transform.GetChildCount()];
squadMembers = new int[transform.GetChildCount()];
for (int i = 0; i < transform.GetChildCount(); i++)
{
formationPointArray[i] = transform.GetChild(i);
squadMembers[i] = i;
}
}
// Update is called once per frame
void Update () {
}
}
You would need to create an empty game object and put this script on it then have each of the child objects as the points where they form.
I’ve seen methods before where you affect the target locations for the gameEntities. Essentially you work out a mid point for all the selected gameEntities that are to be moved at the time you tell them to move, and then work out an offset from that midpoint for each gameEntity. You then give each gameEntity a target movement location of the overall target + their specific offset. It might not solve the bumping whilst moving (although they should all be wanting a slightly different route to/from their own respective start/end location) but it should stop them fighting at the end as they have their own targets to get to.
You should look into steering behaviors. Furthermore you could start by looking at each unit in regard to the others and create direction vectors that you add to the the end point in your path (normalized or something) then they will go to each their spot around your “mid point”. All this would be more clear if you looked at steering behaviors.
I found this series handy when looking into steering behaviours: Game Development Learning Guides | Envato Tuts+
It’s a good starter i think.
Thanks guys I’ll have a look at a few of those options and mess around with a them to see which one I can implement the best, if I get stuck I guess I’ll come back and ask try again 