- Home /
Question by
SHIMMY · Jan 14, 2013 at 07:05 PM ·
collisioncharactercontroller
No Collision with character controller
I have a character who is using a character collider, when they collide with this sphere, the sphere is meant to instantiate an object, and destroy itself, but without the collision, nothing happens. It is even set to print, and yet it doesn't. Here is the code: (is that the problem?)
function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.tag == "Player")
{
print ("FOOD!");
Instantiate(BodyPrefab, GameObject.Find("Snake").transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
Comment
Do you have a rigidbody component on the object? Also a collider not set to be a trigger?
Best Answer
Answer by Imankit · Jan 19, 2013 at 05:14 AM
For character Controller OnCollisionEnter does not work.. Use this..
function OnControllerColliderHit (collision : ControllerColliderHit) {
{
if(collision.gameObject.tag == "Player")
{
print ("FOOD!");
Instantiate(BodyPrefab, GameObject.Find("Snake").transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
Your answer
Follow this Question
Related Questions
Make Character Controller a Box? 2 Answers
My Character Controller Is Warping Randomly (/w video) 0 Answers
Collision and character controllers 0 Answers
Collision With Character Controller 4 Answers