Nov
13
2012

Place Objects on Space With Mouse

If you want to instantiate objects on empty space, you cannot use Raycasts (no colliders to hit).
But you can use ScreenToWorldPoint() with adjustable distance from camera.

(Or you could put invisible collider there..and if you need to adjust distance, move the collider..)

Webplayer:
http://unitycoder.com/upload/demos/PlaceObjectsOnSpace/

Download source:
instantiateAtSpace.unityPackage


Related Posts

About the Author:

.fi

2 Comments + Add Comment

  • I struggled with this a while back. Any way to prevent cubes from being build inside other cubes, without using an invisible collider out in front of the camera?

    The idea is a first person shooter, with some base building. So having a collider out in front seemed to basically act a shield to enemy fire.

    • some ideas to try,
      - If you use grid, then keep array of filled grid cells, so cannot place on them
      - Or, if no grid, keep list of objects and check if user tries to insert new object too close to existing (radius, check each building from list (basically find nearest and calculate distance)
      - Or have colliders/triggers, and then use layers to disable bullets from colliding on them

Leave a comment