How to get offset postition after rotation ?

Hi , I have a spawnPoint where I spawn gameobjects in columns with offset. I am able to spawn them with the right offset when the spawnPoint has no rotation. But run into trouble when the object has rotation. How to get the direction of offset when the spawnPoint has rotated. Please refer image and my code below. At it for hours:(

Vector3 newPosition = new Vector3(SpawnPos.position.x + OffsetPos.x, SpawnPos.position.y + OffsetPos.y, SpawnPos.position.z - OffsetPos.z);

There are a couple of ways about this:

If your objects spawn as children of the spawn point then you can set them exactly as you do now but assign their LOCAL position for the offset. This is their position relative to their parent transform, which in this case would be the spawnpoint. Since the spawn point is rotated with its right direction pointing slightly down, when you assign the gameobject’s local position to right, it would be right and down a bit just like in the second image.

spawnedObject.transform.localPosition = newPosition;

Alternatively, if your spawned objects are not children of the spawnpoint, you can still use the spawnpoint’s transform in order to change your offset to be relative to it by using the InverseTransformDirection function which changes a direction from local space into global space. This will answer the question ‘if our spawn point is rotated and we have a vector that’s locally pointing right then what is this vector in the real world’:

Vector3 transformedOffsetPos = transform.InverseTransformDirection(OffsetPos);

Hope this helps and please let me know if there are any parts you don’t understand :slight_smile: