- Home /
Object won't collide with FPS Controller
Hi everyone, I'm still super new to Unity, so sorry if this question sounds dumb or anything, but I've been experiencing a lot of trouble with the problem that an object won't detect collisions with the FPS Controller. Here's the object's code:
using UnityEngine;
using System.Collections;
public class BulletOnGround : MonoBehaviour {
void OnCollisionEnter(Collision collision){
Debug.Log ("Collision Detected");
if (collision.gameObject.name==("FPSController")){
Debug.Log ("Collided With Player!");
Destroy (gameObject);
}
}
}
Any help at all would be appreciated, thank you!
Answer by Paul_Eliasz · Oct 17, 2016 at 02:09 PM
Hi @Gaming_Dragon,
There is an alternative and easier way to detect a collision. Simply use OnTriggerEnter() function and remove if statement from inside your code! Your aim is to enter and destroy your detected object in front of you(Make sure that your collider for "object being destroyed" is on). However if you use OnCollisionEnter() function this will only collide with your object without destroying it!
using UnityEngine;
using System.Collections;
public class BulletOnGround : MonoBehaviour
{
void OnTriggerEnter()
{
Debug.Log("Collision Detected");
Debug.Log("Collided With Player!");
Destroy(gameObject);
}
}
Hopefully this solves your problem :)!
Paul_E
Answer by b1gry4n · Oct 17, 2016 at 02:12 PM
Make sure in your collision matrix (Edit>Project Settings>Physics) the layers you have these 2 objects on are able to collide.
At least one of the objects needs a rigidbody attached.