- Home /
Checking collisions between two objects that don't have rigidbodies
Hello all. I know the question "how do you check for collisions between two colliders" has been asked a million times, but unfortunately none of the answers I have seen satisfy my problem. You see, at the core of what I am trying to do is a building block game, an easy example would be minecraft. However, unlike minecraft my system is not limited to blocks. I have many different shaped components such as thin plates, 45 degree angles, I-beams, etc. I have been thus-far using a Physics.CheckSphere function to make sure you don't place blocks and the like within each other. Problem is, with some parts, especially plates and 45 degree angles, a sphere check doesn't work very well at all. My next idea was to use Collider.OnCollisionEnter but that only works with non-kinematic rigidbodies! Since this is a builder without moving objects, rigidbodies would be problematic. In order to help illustrate my point, I have thrown together a picture that illustrates the problem.
As you can see, the slope is obviously not overlapping with the cube beneath it. Whereas the sphere collider worked for the cube on the other side, when you get a more irregularly shaped object such as the slope the system falls apart.
Is there any way to properly check for collisions using the part's collision mesh instead of a Physics.CheckSphere?
Note : You may have noticed that I was able to place a thin-block onto a ramp down there. That is because the Physics.CheckSphere checks collisions with the other object's mesh. So for placing objects ONTO something, the system works fine, so long as the object you are placing can easily fit a sphere inside it without problems.
Answer by MirrorIrorriM · Dec 18, 2011 at 07:36 PM
I figured out that, while OnCollisionEnter requires one of the colliders to have a non-kinematic rigidbody, OnTriggerEnter does not; a kinematic rigidbody WILL suffice. So I was able to make the object I am placing a kinematic rigidbody that has a trigger for a collider. In addition I had to shrink every object to be 99.99% of its normal size so the objects don't collide with each other by just being placed. Although this leaves a visible crease for some objects, I was able to incorporate a black line into the texture to compensate. So yeah, problem solved!
Your answer
Follow this Question
Related Questions
How may I observe expected physical interactions while using Rigidbody.MoveRotation()? 1 Answer
Object Flies into Air Upon Collision, or goes through hill depending on isKinematic settings 1 Answer
How to setup character Collisions? 2 Answers