Hi all,
I’ve spent the last couple of days trying to get this and I’m not sure if I’m overlooking something really simple or just going about it incorrectly.
I have a number of objects that are grouped together (think units in a regiment, each unit is its own gameobject).
I have a script which finds the middle point of this regiment, and then on right click rotates all of these objects around that middle point. So far so good (or so it seems).
The problem comes when I add in the fact that the whole regiment follows the mouse until it is “placed” - so if I right click while this is happening I want it to be able to both rotate and remember the rotation.
Unit placement is done via mouse co-ords from a raycast and adjusted based on the middle point I spoke of earlier. This has the habit of ignoring the rotate around and just resetting it to 0.
I’ve experimented a lot with finding a relative point of the unit
transform.RotateAround(_rotationPoint, Vector3.up, _rotateVelocity * Time.deltaTime);
_currentRotation = _rotationPoint - transform.position;
this is the rotatearound script, which then stores its relative position from the current middle point of the regiment.
Then when the mouse moves we get a value from the ray, and re-draw the units out into their positions and then finally add the relative value from the stored part (so ideally we get a well spaced out group of units/gameobjects facing another direction).
if (_currentRotation+ newLocationSpot != transform.position)
{
newLocationSpot.x = newLocationSpot.x + _currentRotation.x;
newLocationSpot.z = newLocationSpot.z + _currentRotation.z;
}
the result is mainly a random spacing between the units (from being piled on top of each other, to having double the space of normal), jerky rotation and inaccurate rotation.
I can post more code if needed, but thought i’d describe it first and see if someone had a novel idea/solution that I was missing!