In Unity, I've been working on procedurally generated planets made out of cubes. After a long time of testing and tweaking, I have it pretty much where I want it. The problem is, I want these planets to move around a star, which works okay, but I also want these planets to spin. In my code I use the position of where a raycast hits to find the block that would be built / broken. When rotating, though, there is no way for the planet to know that its rotated, meaning when you try to break a block on one side, it still thinks your breaking blocks on wherever that was originally. Is there any way to have it track its own rotation and use that to figure out (accurately) which block is being chosen? Or do I have to approach the problem from another angle?
Current method of replacing blocks:
public void SetBlock(Vector3 pos, Block block)
{
float x = pos.x;
float y = pos.y;
float z = pos.z;
x = Mathf.RoundToInt(x);
y = Mathf.RoundToInt(y);
z = Mathf.RoundToInt(z);
x = x - this.transform.position.x;
y = y - this.transform.position.y;
z = z - this.transform.position.z;
pos = new Vector3(x, y, z);
blocks[(int)pos.x, (int)pos.y, (int)pos.z] = block;
UpdatePlanet();
}
Thanks in advance!