Mesh colliders not working (imported .FBX object)
I'm making a katamari like game with objects like a slide and a swing, so I figured a mesh collider would be the best way to go.
So when the ball I'm using is bigger than the colliding object, the ball should pick it up. That's not happening when I'm using mesh colliders. I can collide against it, but it just wont pickup. What am I doing wrong? (I already tried adding a new mesh collider and it does work with a box collider but since I want to go under the swing when I'm way smaller than it, box collders aren't good).
using UnityEngine;
using System.Collections;
public class PickupObject : MonoBehaviour {
public GameObject playerObject;
private GameObject pickup;
private float volumePickup;
void Start() {
playerObject = GameObject.FindGameObjectWithTag ("Player");
pickup = this.gameObject;
pickup.gameObject.tag = "PickUp"; //put this tag onto the object the script is hanging onto
volumePickup = pickup.transform.localScale.x * pickup.transform.localScale.y * pickup.transform.localScale.z;
}
void Update () {
//volume sphere: r^3 * pi * 4/3 is bigger than the pickup
//divided by two since I only have the diametre
if ((((playerObject.transform.localScale.x / 2f) * (playerObject.transform.localScale.x / 2f) * (playerObject.transform.localScale.x / 2f)) * 3.14f * (4 / 3)) > (volumePickup)) {
pickup.gameObject.GetComponent<Collider> ().isTrigger = true;
}
}
}
Answer by JiskaBaeten · Feb 01, 2017 at 09:20 PM
I seemed to have figured it out by myself (not sure how I should close this question now ^^;;).
I didn't notice that Mesh Colliders had to be Convex in order to use triggers and since I'm turning the trigger on of anything becomes smaller than the ball itself, it wouldn't work. Still glad I figured it out.