Target a point in space relative to gameObject

Hello

I am making a demo of a sci-fi game in space.

I have a missile, that flies to certain target. I also have a spaceship GameObject. Inside this spaceship GameObject there is a ShipBody with Box Collider, and this Collider is the target for the missile. When I fire the missile it aligns to the target and moves slowly to it - this works fine for me. But after launching multiple missiles at once I saw, that they all fly straight to the center of the ShipBody, and it looks unrealistic. So I made a function that when a missile is acquiring target it also generates random offset inside the mesh of the Collider, so missiles seem to hit different spots of the ShipBody - and it works fine.

The problem is when I rotate the ship. It still flies to the position+offset, but it do not recognize the rotation of the main object. I hope image will clarify this.

I dont want to do this by just creating empty GameObject inside SpaceShip - what if there will be hundred missiles and dozens of ships. I dont want to litter the scene with useless GameObjects. I will do this, if this is the only way, but If there is more elegant one, I will try to implement it.

you are going to need to use local position. local positions are relative to a parent object’s rotation and position. if you dont want to use empty objects as markers then you can use transform.InverseTransformPoint to store a local position relative to the ship.

you can then use transform.TransformPoint to get the point back with consideration of the ships position and rotation.
transform.InverseTransformPoint

transform.TransformPoint

You can multiply the random offset by the spaceship transform.right, transform.up and transform.forward every frame to get an updated offset. Those values consider the gameObject rotation.