This question was
closed Apr 06, 2016 at 11:18 AM by
UncleGubbsy for the following reason:
Question is off-topic or not relevant
Question by
UncleGubbsy · Apr 04, 2016 at 07:47 PM ·
vector3listforeachindexof
Total war Style Movement System with Right Click
/*
pseudo code for Total war syle -Right Click and Drag Move-
Right Click and Drag to place the units where you want them in a straight line, each offseted from one another by how far you drag the line.
public List<GameObject> unitsSelected = new List<GameObject>(); *already made*
int offset
This is used for the left click select marquee. There is more to it but, all I need is to duplicate it and use the selection.x variable.
I changed the left click to a right click
-----------------------------------------------
if (Input.GetMouseButtonDown(1))
{
startClick = Input.mousePosition;
}
else if (Input.GetMouseButtonUp(1))
{
startClick = -Vector3.one;
}
if (Input.GetMouseButton(1))
{
selection = new Rect(startClick.x, InvertMouseY(startClick.y), Input.mousePosition.x - startClick.x, InvertMouseY(Input.mousePosition.y) - InvertMouseY(startClick.y));
if (selection.width < 0)
{
selection.x += selection.width;
selection.width = -selection.width;
}
if (selection.height < 0)
{
selection.y += selection.height;
selection.height = -selection.height;
}
}
-----------------------------------------------
This is what I have a question about.
if(Input.GetMouseButton(1)){
Simple Raycast here.
offset = selection.x / 2; The selection.x above ^^^^ Also divide by 2 to make it a bit smaller and more useful.
foreach(GameObject unit in unitsSelected){
Create a new Vector 3 or empy gameobject (essentially a transform) and assign each unit in unitsSelected their own new transform.
So each unit will have a place to go after you release *right click*.
Vector 3 unitTransform = hit.point + offset * unit.IndexOf(unitsSelected); Maybe this will work? If I were to only add the offset from where you click all the units would be in the same place, so,
multiplay by the place those units are in, in the list to find where hey should be in the line starting from 0.
So the first should be on hit.point. because multiplying by 0
Second should be an offset away because multiplying by 1
So on.....
When that's all done, then we can talk about rotation.
We need to find the center point of all the units that are selected.
There was another post about this.
http://forum.unity3d.com/threads/rts-unit-formation.169319/
Velo222 gives a rough idea on how to go about it.
Essentially rotate the new Rectangle we made/new line, around the center point of only the Units that are selected. I have no clue on how to do this. This isn't priority anyways.
When that's all done if(Input.GetMouseButtonUp(1)) Move unit.transform.position to unitTransform/new Vector3 we made?
}
}
My main question is just how to go about this. Am I on the right track or should I steer a certain way somewhere else. I'm not looking for actual working code, I just want some ideas you might have on how to solve this problem. If anyone has any tutorials about this please share them, I haven't found any specifically about this.
Comment