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
2 Comments + Add Comment
Leave a comment
Recent posts
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
- Check if point is inside polygon 2D (using line intersection)
- UnityHub: Enable Create Project Button (without having to select Cloud Organization)
- UI: Make Tooltip background fit Text content length
- Pong-Wars in Unity
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub)
- UnityHub: Add support for custom project title (instead of folder name) or use ProductName
- Testing Unity MUSE AI
- QR Code Generator Online
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