Hey guys, I’m having some major issues, and I am starting to think it is not my code:
Model
|
--- A Box Collider
|
--- B Mesh Collider
|
--- C
Here is what is going on:
I have a linecast that turns a line renderer red when looking at ‘A’, and yellow when looking at ‘B’ (meaning you are close to aiming at A).
The line renderer works just fine-- it knows it has collided with ‘B’ and turns yellow.
However, the object that fires which is supposed to collide with ‘B’ acts funny.
It will correctly bounce OFF of ‘B’, but most of the time a message is never sent to my script-- but sometimes it does, it is just very finicky.
Diagnostically, I have merely changed my collider from a Mesh Collider to a Box collider and it works just fine (except now that I can no longer hit ‘A’ because of the shape of the object).
I have also changed the mesh to something simpler, but it still happens-- the projectile bounces off of the object, but ‘OnCollisionEnter’ is only sent about 50% of the time.
Update:
I noticed that the docs specificy that one of the colliding objects must have a rigidbody attached, and my projectile does-- that is not the problem.
However. I noticed that when I attach a rigidbody to Object ‘B’ that OnCollisionEnter does get called more frequently , if 100% of the time (it is hard to tell). This is n ot an optimal solution since I do not want the object to move due to physics collisions.
Set the rigidbody.isKinematic = false. That way it is unaffected by physics. Otherwise, your problem sounds like you are doing something wrong. So long as you have the correct colliders, for both the projectile and B, it shouldn’t be Unity’s physics. Check the docs again, http://unity3d.com/support/documentation/Components/class-MeshCollider.html
At the bottom of that page is a collision matrix which shows when collisions occur and between what collider types. If you do have it correct, make sure the projectile isn’t so fast it’s passing through B in a single frame. See here - http://www.unifycommunity.com/wiki/index.php?title=DontGoThroughThings
Hey–
Thanks for your reply, but I don’t think it is either of those.
I’ve read that document before, and I double checked it today.
I did set kinematic to true, and it does keep Object B from moving. My projectile has a sphere collider on it, with a rigidbody. Object B has a mesh collider on it and no rigidbody.
According to the end of documentation page, my projectile is a Rigidbody collider, and Object B is a Static Collider, which means a message should be sent (as it sometimes is).
I’ve experienced the Objects going through things in the past, and my projectile is not moving fast-- otherwise it would pass through Object B into Object A.
Here are my current guesses:
- There is some sort of a bug with Unity’s physics engine in the update
- There is a bug with C4D exporting .OBJ / FBX, resulting in the PhysX engine missing something
- I’ve set something wrong in the inspector (I have no idea what since it works sometimes)
I need to stress that sometimes it does work, just not all of the time.
I’m not sure if I mentioned this, but on Object B, the mesh is about 250 triangles, but I swapped out the collider for something with about 60 triangles to make it more efficient.
Do you have any other ideas? I’m open to trying just about anything.
I just double checked my projectile and notice that the collision is set to “Continuous Dynamic”, so it is definitely not going through anything.