Search Unity

Random Object Placement within Non-Rectangular Plane Object?

Discussion in 'Navigation' started by jcam828, Apr 29, 2019.

  1. jcam828

    jcam828

    Joined:
    Feb 26, 2019
    Posts:
    5
    I'm not sure if this is the right sub-forum, but I want to randomly spawn 3D objects within the precise boundaries of 2D flat shapes. The 2D shapes are irregular shapes (polygons without curves) rather than square or rectangular. So the 3D objects can arise anywhere within the area of the 2D shapes but not beyond their carefully determined edges. Any ideas?
     
    Last edited: Apr 29, 2019
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Not the right forum indeed, but you could actually abuse the NavMeshSystem to get this done. If your polygons would be used for the NavMesh, you could just generate a random position and then use NavMesh.SamplePosition to project that point onto the NavMesh. Keep in mind this is a bit of a hacky solution, but if it's stupid and it works, it isn't stupid.
     
  3. jcam828

    jcam828

    Joined:
    Feb 26, 2019
    Posts:
    5
    Sorry about the wrong forum. I'm new. But thank you, Yandalf.