- Home /
Multiple colliders on a single character?
I've read it's okay to have different kinds of colliders on an object- mesh collider, box collider, capsule, etc. but putting four box colliders on a single object is a no-no.
So what exactly do you do in terms of colliders for melee combat? I figure attaching empty game objects to the hands of the character, for example, and giving those their own colliders. Would this cause problems? How do action games and fighters usually go about handling these types of collisions?
Answer by jakeflaze3859 · Jun 29, 2015 at 10:29 PM
It should be something like this. Let's say you have two collision objects one for each hand, you would attach the script below to each collision object. Then you would set the Collision prefab transform variable from the left hand to the right hand, and the right hand variable to the left hand. This prevents collision from one transform to another, but still allows collision from other objects. Also if you're just wanting a more detailed collision shape for the hands, then you could use a 3d model to make a mesh collider instead of using multiple colliders on one object.
using UnityEngine;
using System.Collections;
public class AvoidSelfCollision : MonoBehaviour {
public Transform CollisionPrefab;
void Start() {
Physics.IgnoreCollision(CollisionPrefab.GetComponent<Collider>(), GetComponent<Collider>());
}
}