- Home /
OnCollisionEnter not being called, between a Rigidbody and a Box Collider
Hi Guys,
For the love of me I can't figure this out, I've been searching around the forums like crazy too. Everything I read seems like it should work, however OnCollisionEnter never gets called.
I have an instantiated Projectile with a Rigidbody attached to it, this Projectile has a script on it with the OnCollisionEnter method. This script inherits from MonoBehaviour.
I have 3 cubes with Box Colliders on each of them.
The Projectile simply passes straight through them, and there is no OnCollisonEnter method being called. Here is my code, I have included the entire script as it is relatively short, even though I doubt 99% of it will be of importance.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ProjectileBehaviour : MonoBehaviour {
private List<Effect> effects;
private float distance;
private Vector3 start;
public void activate(List<Effect> e, Material m, float d){
this.effects = e;
this.renderer.material = m;
this.distance = d;
start = transform.position;
Debug.Log ("activated!!");
}
void Update(){
if(Vector3.Distance (start, transform.position) > distance){
Destroy (gameObject);
}
}
void OnCollisionEnter(Collision other){
Debug.Log ("collision!!");
UnitVars targetVars = other.gameObject.GetComponent<UnitVars>();
foreach(Effect e in effects){
e.apply (targetVars);
}
Destroy (gameObject);
}
}
it has a rigidbody, does it need a rigidbody as well as a collider? I thought the rigidbody acted as one
There is no way for it to calculate collision without a collider component.
oh wow, okay, thanks! easy fix then. I'll give it a try :)
Answer by LukaKotar · Apr 05, 2014 at 12:09 PM
Does the projectile have a collider?
I had to add a collider to my Projectile, even though it has a rigidbody, it still needs a collider component or it won't be able to calculate collisions.
Thanks to Luka$$anonymous$$otar for the fast response and amazing help!
hi, i have the same issue. my prefab has a sphere collider,rigidbody and my player also has a sphere collider and rigidbody.
the OnCollisionEnter() does not get called.
Please Help!!