In my 3D game I want the character to be able to teleport to a random location in the scene. There are a few challanges:
1.) The character may not teleport into the air above a valley or into a hill.
2.) The character may not teleport into the traps, trees, wall of the houses or any npc.
3.) At least traps and trees will be created randomly each time the player starts a new game.
4.) The npcs are moving around.
My solution is:
- After getting my random-Vector3, I can set the y-axis to 1 above the ground, after getting the position of the surface at that x,z coordinates.
- Then I can test, if the space is currently used by any object.
- If not, then I can set my fps-controller position = new Vector 3 position
I think that… works. But thats it. Is there any more elegant approach than just that brute-force calculation? Especially on more crowed or narrowed maps, I might run into timing problems and end up inside an npc or with a lag.