- Home /
Two gameObjects in same place [Problem]
Hello,
I created a house and the player can add objects inside this (instantiating prefabs), but the gameObjects appears in the middle of walls or in another gameObjects.
i tried this code:
function OnTriggerStay (other : Collider) {
Destroy(gameObject);
}
But the object isn't destroyed, still alive.
Thanx.
What are you trying to destroy? When you place an object, you need to know that walls and other objects are not colliding with it, or if you don't want to handle that, you would need to 'push' out new objects colliding with your existing ones, once you identify a collision, so the overlapping would not occur.
Answer by roamcel · Apr 10, 2012 at 04:28 PM
What you're experiencing might come from colliders and rigidbodies. If you instantiate an object with a collider and a rigidbody, inside another object with a collider and a rigidbody, the two INTERSECT and tend to push eachother off.
To avoid this, place the prefabs on different layers (or use any such alternative), and use the layer collision matrix
Your answer

Follow this Question
Related Questions
Always have GUI Texture at Said Place Regardless of Resolution 1 Answer
Find gameobjects by tag, and destroy if in the distance of a certain game object... 1 Answer
Grouping GameObjects by script 1 Answer
Empty Parent GameObject Moving with Child 1 Answer
How to get all the GameObjects positions into a .txt file? 2 Answers