- Home /
Instantiated objects ignoring collisions randomnly o.O
Hi guys!
I'm a bit lost here, I'm instantiating objects that are supposed to fall and hit the top of a cube. I have 4 prefabs that I instantiate randomnly at random positions above the cube. Then they fall and some of them hit the cube and stay there... some others just cross the cube... and ignore all collisions... I have no idea what this is happening... Do you have any idea?
I'm just instantiating using the usual initialization
GameObject newInst = GameObject.Instantiate(objctList[selectedIdx]);
newInst .transform.position = position;
....
Thanks!
Answer by Raresh · Mar 20, 2016 at 09:57 PM
It happened to me once when I started and wanted to make a cup thing that can hold spheres. The reason I think it is is that once the objects move fast enough, the physics engine doesn't detect any collisions because they pass through each other(because of the speed). I can think of 2 ways of solving this:
1) If the object they are falling on is a ground static type, make it a cube, and make it thicker so that it can detect the collision better
2) Make a raycast from the moving object to the target, once the raycast doesn't return that it hit the target, it means it passed it and should've stopped (if you keep the previous position you can teleport it back to the last known position)
mmmm it makes sense.... shouldn't happen, but it makes sense if that is the case. Thanks for the reply!
Initially the ground was already an object of the type cube and it was still allowing objects to pass through... I ended fixing the problem in another way... created another cube that is just slightly below the first "ground"...With both cubes, apparently most of the objects already stay in the "correct" place, i.e. on top of either cubes... I don't particularly like the solution, but it's one way to fix the problem. This way I could avoid the second solution :)
Answer by Rob2309 · Mar 23, 2016 at 11:02 AM
If your falling cubes have RigidBody attached to them, you can just change the Collision Detection from Discrete to Continuous... This should fix your problem as long as the floor they are falling towards does not move :)
Your answer
Follow this Question
Related Questions
Instantiate random object from Array 2 Answers
Overlapping Prefabs 0 Answers
Need help instantiating enemies between random locations 1 Answer
How can I Instantiate and do it in a random spot in a random spot? 2 Answers
Instantiate random prefab ONCE 2 Answers