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 :slight_smile:



You could use this script as a workaround:


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.

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);


transform.parent.GetComponent<Rigidbody>().AddForceAtPosition(Vector3.Scale(collision.relativeVelocity,new Vector3(mass,mass,mass)),collision.rigidbody.position, ForceMode.Impulse);