Unity 5 : Non-convex mesh collider & Is Trigger - unity3d

I'm having some troubles checking the "Is Trigger" option on a non-convex mesh collider.
I looked for an answer on the internet and found something like :
Unity 5 does not support that because the updated PhysX does not allow it.
(https://forum.unity3d.com/threads/how-to-enable-trigger-on-a-mesh-collider.347428/)
I was wondering if there was a solution now? Since the post is kind of outdated?
I hope you'll be able to help me :P
Thank you in advance,
Axel

A mesh collider can collide with a primitive collider (box, sphere, capsule) but there is no way to have two mesh colliders register a trigger or collision.
You'll need to use compound colliders to approximate the shape. IMO although it seems imprecise at first in practice you hardly notice if your collision area is slightly outside of your mesh. Performance wise multiple primitives (on anything other than mobile at least) are next to nothing so don't be afraid to use as many colliders as you need to approximate your shape.

Related

From Blender mesh to Unity

I'm creating my terrain in Blender, as I feel more comfortable with it than using Unity's built-in tool. I have this mesh now, and I've implemented the LOD feature as well. The next problem to fix is the collider. I want to use the mesh collider for it. But I'm worried about performances. I split already my terrain in "chunks" each with its own LOD. I need to apply to each square a mesh collider.
What do you think about it? And also do you have any optimization advise?
On YouTube and on some Assets on the AssetStore, I can see a lot of modular terrains packages, and once I checked the mesh that they use, I can see that they are using mesh colliders everywhere.
Extra question: should the mesh be static?
Thank you guys for your time. To some, they might seem such stupid questions, but from someone who is starting now...Well, they still represent a big challenge.
I don't think it will be a problem as long you create a mechanism to deactivate the unnecessary, and unused parts. Look also Ocullision culling and make all the terrains static.

How do box collider collisions work mathematically?

I want to know how the Box Collider works in Unity. I have read all of the Unity documentation and PhysX documentation but there are not any detailed explanations as to exactly how they work (possibly because it's confidential IP).
How does a box collider know when it is intersecting/overlapping another box collider?
What metric is actually measured to know when a collision has taken place? Does it look to see if there is a point or vertex in the box collider is inside the volume of another collider? If so how does it know that a vertex is within the volume of another collider?
What are box colliders made from? Is it lots of small objects put together or is it one big object?
​
Thanks for your help in advance

Rigidbody2D or raycasting?

I am working on a 2D game that involves many blocks that stack and collide on eachother and the player. I am currently using Rigidbody2D on the blocks for dynamic collisions but I am not a fan of how the dynamic physics include the "bounciness" in the elastic collisions. Also, there is an inherent push-force as well as other unfavorable push physics that are too "realistic".
I am wondering what is the best way to handle my predicament to remove the bounciness and push elements of the rigid bodies. I've tried adjusting the block's masses and bounciness physics but no luck. Is there a way to set them all as kinematic or disable these realistic effects somehow and still have them collide via rigidbodies? (Kinematic would be great if they were able to collide with each other) Or will I have to create some sort of raycast based block physics handling script? Or is there an even better solution to creating this very primitive physics structure that I am not seeing?
Thanks for any and all help!
The only way I could think of solving your problem, such that you have complete intuitive accuracy, is to write your own Rigidbody controller. Of course you can still reuse the Box colliders.
Once you've decided on a collision detection method and manifold generation working (raycasting maybe), this link details the impulse resolution you need.

Determine on which collider the collision has taken place

I have a gameobject with two sphere colliders attached. One has IsTrigger checked and the other not.
I want to execute different set of statements when collision occurs with different colliders. For example I want to play different sound for both different collisions. Is there any way to achieve it?
I tried OnTriggerEnter() but unfortunately it is called for both type of collisions since other colliding objects have triggered colliders. I just thought if we could somehow find out on which collider of the gameobject the collision has taken place we will be able to achieve it.
So is there any way to get through with this?
I have been using Unity for years and faced tons of problems like this, related to bad software design. I hope Unity guys will handle physics more carefully in future releases.
In the mean time, you can use Physics.OverlapSphere and Physics.CheckSphere to manually check if there is something that collides with your object. Remove the collider that you are using as a trigger and use these methods instead of OnTriggerEnter. This is a bit hacky, but this will do the job I think.
Make your colliders visible in the inspector (make them public or add [SerializeField] before it) and then tie in the colliders to the code that way.
Then, in your collisions, compare the colliding objects against your variables that are holding the colliders for you to keep them separate.
To detect for source trigger in OnTriggerEnter, you must use workaround with multiple gameobject hosting trigger and satellite scripts.
Allow me to link to my answer on gamedev SO:
https://gamedev.stackexchange.com/a/185095/54452

Fighter Game in Unity3D - Fighter hit opponent [unityscript]

I'm making a fighter game in Unity. When I punch I need to find a way for Unity to detect that if I'm hitting the opponent. The problem is that I don't seem to find a way to do so.
Isn't there a way to make it detect if the meshes are touching each other or maybe some better way.
Do you have any ideas?
Regards,
Robert Dan
I would take a look at Physics.SphereCastAll. Sphere casting is similar to ray casting. Consider sphere casting a thick ray cast. The idea behind this is to cast a sphere from where the punch originates in the direction that the punch is going. If any colliders are returned from the function, then you know that it hit something so you will just have to check that what it hits satisfies the right conditions (i.e. is another player).
The most obvious solution is to add mesh collider and kinematic rigidbody to the mesh you're attacking with and use OnCollisionEnter to detect collisions with other rigidbodies.