How to generate a random vector3 with the same z distance relative to a map with rotation?

How can I randomize the spawn location(x) of my gameobject while maintaining it’s z distance from the map? Doing a transform.position.z won’t do since the spawner and the map have a rotation.

Vector3 spawnLoc = new Vector3(Random.Range(minX, maxX), transform.position.y, ?????);

alt text

Does that mean your map is moving and rotating?
Why not use relative positioning? If your spawned object is set as a child of the map, you won’t need to know the rotation or position of the map. Just the relative position of your object map wise.

Why don’t you keep the map and spawner rotation at 0 and just rotate the camera? Same visual effect, easier maths.

Hi guys solved it myself this is what I did.

    public float minX = -7.45f;
    public float maxX = -1.45f;
    float prevX;
    float prevZ;

    void Start () {
        prevX = transform.position.x;
        prevZ = transform.position.z;        
	}

 void Generate() {

        float newX = Random.Range(minX, maxX);
        float newZ = ((prevX - newX) - prevZ) * -1;

        prevX = newX;
        prevZ = newZ;

        Vector3 spawnLoc = new Vector3(newX, transform.position.y, newZ);
    }