- Home /
Unity 5 workaround for concave colliders
As excited as I am to try out Unity 5, I can't.
My game is set in space and I have some detailed meshes as the ships. These meshes cannot practically be split up into convex meshes, the model is just too large with too much detail.
I am thinking about a workaround but I beleive my limited knowledge is getting in the way. Under the assumption this method can be made to work it is a fairly decent and simple solution without any external assets etc.
Can this work?
Firstly, the model meshes need to have a parent which is a child of the Prefab. This is so that I can attatch a script to their rigidbody Object, that is still a child of the ship. This rigidbody in use for the meshes must be set as kinematic due to the Unity 5 update. I have applied a second rigidbody to the Prefab (parent Obj). The Prefabs rigidbody can utilise the physics and the models rigidbody allows concave collisions. I am creating a basic script, which I need help with, that will pass collisions on the model rigidbody to the Prefabs rigidbody, allowing the collisions to effect the ship.
The script is applied to the model kinematic rigidbody, on all objects needing concave colliders.
Heres what I have so far..
using UnityEngine;
using System.Collections;
public class ScriptPassCollision : MonoBehaviour {
void OnCollisionEnter(Collision collision) {
float mass = collision.rigidbody.mass;
transform.parent.GetComponent<Rigidbody>().AddForceAtPosition(Vector3.Scale (collision.relativeVelocity,new Vector3(mass,mass,mass)),collision.rigidbody.position);
}
}
This seems to be working to a degree..
The effect seems way too much, is my math wrong? the ship rotates, but stops again soon after? very confused here and may have external influence.. and lastly the ship doesn't move as i would expect add force to do?
Feel free to leave suggestions in rewriting the idea altogether.. I've stayed up too late :)
Thankyou,
-Aaron
"This rigidbody in use for the meshes must be set as kinematic due to the Unity 5 update." --> can you explain further?
error since upgrading to 5: Non-convex $$anonymous$$eshColliders with non-kinematic Rigidbodies are no longer supported in Unity 5.0
The error points to every concave $$anonymous$$eshCollider in the scene
It used to work, just not between two concave colliders. You could have, for example, a complex house with a mesh collider as concave and the player and other objects inside would collide with it as long as those objects are convex.
As my unity editor is now I simply cannot have a concave mesh collider with a rigidbody at all.
Eric, is 5.0f4 a $$anonymous$$or update since 5 became available or is that what was released? Not with my computer at the moment. Also what you're saying is also correct for me in terms of the is trigger box.
-Aaron
I can attest to the fact that non-convex mesh colliders with Rigidbodies not set to "Is $$anonymous$$inematic" worked fine and registered collisions in 4.6, and not in 5.0 From what I understand, it was a Physx edict. We are in a similar world of hurt, trying to chose the best solution to this huge problem.
Answer by stanzy · Feb 23, 2017 at 08:08 AM
You could use this script as a workaround:
http://productivity-boost.com/DownloadNonConvexMeshCollider.html
Note: The example scene needs $$anonymous$$or tweaking to get working in the latest version of Unity. But the script seems to work fine.
Answer by Eric5h5 · Mar 04, 2015 at 07:47 PM
There are no issues with using concave colliders in Unity 5. Concave triggers are another matter, but you don't seem to be using those.
Error: Non-convex $$anonymous$$eshColliders with non-kinematic Rigidbodies are no longer supported in Unity 5.0
I need physics.. can't use kinematic rigidbodies.
I don't even use triggers on the $$anonymous$$eshes the error is pointing to
I open a new project. Create a blender model, simple cube with an indent. Load cube into scene. add rigidbody (all settings default) add $$anonymous$$eshCollider (all settings default) Error: Non-convex $$anonymous$$eshColliders with non-kinematic Rigidbodies are no longer supported in Unity 5.0
Nope, so such error here (5.0f4). What doesn't work is non-convex colliders with triggers, but you're prevented from selecting that anyway (Is Trigger is greyed out unless Convex is checked).
Well, according to http://docs.unity3d.com/$$anonymous$$anual/class-$$anonymous$$eshCollider.html, "Non-convex $$anonymous$$esh Colliders are only supported on GameObjects without a rigidbody. If you want to use a $$anonymous$$esh Collider on a rigidbody, it needs to be marked as Convex." - it's not mentioned that this is a change in Unity 5 but, AFAI$$anonymous$$, concave mesh colliders have never registered collisions with other mesh colliders anyway, so the only change is that Unity now prevents you from even getting into the situation of wondering why collisions with your rigidbody concave mesh aren't being registered, because it won't let you create one in the first place...
Accidentally added comment to original question. See that please. Last time I'm replying here on my half dead phone sorry.
Answer by Cephalobyte · Jun 03, 2021 at 07:58 PM
Hey, I know I'm a century late, but I think I have your answer. Right now, you're applying a force every single frame the Rigidbody is inside the collider. You either want to multiply the velocity vector by Time.deltaTime
or add a third parameter at the end of Rigidbody.AddForceAtPosition()
which is ForceMode.Impulse
So the correct formula would either be
transform.parent.GetComponent<Rigidbody>().AddForceAtPosition(Vector3.Scale(collision.relativeVelocity,new Vector3(mass,mass,mass))*Time.deltaTime,collision.rigidbody.position);
or
transform.parent.GetComponent<Rigidbody>().AddForceAtPosition(Vector3.Scale(collision.relativeVelocity,new Vector3(mass,mass,mass)),collision.rigidbody.position, ForceMode.Impulse);
Your answer
Follow this Question
Related Questions
Similar movement to a game (look description) 1 Answer
Distribute terrain in zones 3 Answers
Delaying Physics Calculations (Friction) 1 Answer
How do I make my character controller jump when I use this code? 0 Answers
Crossing Soccer ball system Help 0 Answers