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:

  1. 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).
  2. 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.
  3. 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.
| improve this answer | |
  • \$\begingroup\$ Thanks a lot.. Here are the problems thatI'm facing while implementing this 1.My model has a floor and walls and slabs. I wish to place objects only in walls and slabs and avoid running them into each other and walls of the model. 2. Collision with bounding volume will only return my model and no normals. How to distinguish between walls and floor/slabs. 3. How to decide in which direction to move the the object once collision is decided?? \$\endgroup\$ – simar Sep 2 '13 at 6:40
  • \$\begingroup\$ I believe your first problem is the one I've addressed in my answer. And I think two and three would be better answered as questions of their own, since explaining that in the comments would be difficult. \$\endgroup\$ – MichaelHouse Sep 2 '13 at 7:37
  • \$\begingroup\$ k thanks. If I'm running on android, I hope you using physics wont slow down a lot... I will ask the other questions and mention the link here in the comment \$\endgroup\$ – simar Sep 2 '13 at 9:38
  • \$\begingroup\$ Please give code in the above if possible. using physics in bounding volumes. and I have posted the other questions here gamedev.stackexchange.com/questions/61629/… gamedev.stackexchange.com/questions/61631/… \$\endgroup\$ – simar Sep 2 '13 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.