In my game, the user has to click at a point to place an object (mesh). I can cast a ray and find the horizontal point where the object can be translated and then attached to rootNode to display it. However, the problem is that if the user click too near to another object/scene_wall the object to be placed, runs into it. How can I prevent that?
You should be able to get by with a simple collision check before placing the object. The basic steps of which you'll find below:
- Before placing the object, perform a collision check with a physics body representation of the mesh you're placing (either a bounding sphere, bounding cube or more accurate shape).
- If this collision check collides with the scene, move the target position far enough away from the collision that it will no longer collide. Do the collision check again with the new target position.
- If the new target position also has a collision, you're probably in a location that's too small to fit the object you want to place. Notify the user and perhaps draw an outline of the object to show how it doesn't fit.