Vector3[] points = new[] { new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f), new Vector3(1, 1, 0) };
for (int i = 0; i < points.Length; i++)
{
Transform go = Instantiate(squadMemeber, points[i], squadMemeber.rotation);
}
When i create the squadMemeber i want that the distance between them will be for example 10 from each other. I’m making a triangle formation so i want to make equal distance between the squadMembers but to keep the triangle shape.
Instead of the term pointsXXX when you instantiate the member, use something like pointsXXX * 10.0f; (Edit: above the XXX should be your square bracket around i index dereference but I’m too lazy to go figure out how to post that on this editor)
I did, and the result is a bit strange.
The shape is not really a triangle i mean the bottom character should be in the middle i think.
And the two others are in the air but i want them all to be on ground.
Vector3[] points = new[] { new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f), new Vector3(1, 1, 0) };
for (int i = 0; i < points.Length; i++)
{
Transform go = Instantiate(squadMemeber, points[i] * 10.0f, squadMemeber.rotation);
go.parent = gameObject.transform;
}
Without making * 10 the characters too close to each other and it’s not looks like a triangle at all they are just standing one beside each other. I want to make triangle formation with equal space/distance between each one on ground.
Add jump pack to your soldiers, so players will not find their position strange
Your main problem is that you need to take care of the terrain also to correctly position your soldiers.
So I would suggest to calculate exact position for first guy, using RaycastAll.
Sure, that’s a way. I think for this, if there were “known formation shapes,” I would produce a special script that had semantically named positions in it, and then make instances of a gameobject with blank game objects in each of the holes. I would have a “standing abreast” formation, a “single file” formation, and so on.
Then when you select a new formation, it would tell your party members their preferred offsets. You would control the party (when not in combat) as a single object facing a given direction, and all the other locations would be derivative based on the formation chosen, and the orientation you’re in, etc. Then maybe in combat it all goes free-form until combat is over.
There’s a bazillion ways to get interesting effects and I’ve played games that use quite a few variations on the above.