How to make rotating objects with snapping to grid while the object contains children
Hi there! I want to make a rotating figure that will be able to change its shape(adding cubes as a children) and will snap to the grid. I dont have a clue on how to do that. I've had an idea to rotate it with 4 empty objects around the figure that will be dynamically moving with figure and the figure will rotate over it via RotateAround but another thing is that if i have an empty parent he has no collision for the whole figure and even when i set one up it can change when i add an element(adding cubes to it will be on of the main mechanics). What i have soo far is this rotation over rotatearound https://gyazo.com/7fe79b74878840a5349aa633047d7d28 Minuses of that approach is that i cannot animate it over time which makes this snap movement. Other than that here's my simple code
public GameObject newPosition;
private float currentTime;
void Start ()
{
}
void Update ()
{
if (Input.anyKeyDown)
{
MoveToPosition(0.2f);
}
}
//Moves and rotates the position of the figure
void MoveToPosition(float timeToMove)
{
var currentRot = transform.rotation;
//limits clicks per seconds
if (Time.time > currentTime + timeToMove)
{
currentTime = Time.time;
transform.RotateAround(newPosition.transform.position, Vector3.forward, 90);
}
}
Any help will be apprecieated :)