- Home /
Question by
SohaibTheGame · Aug 12, 2013 at 12:14 PM ·
collidertriggerfunctiononcollisionenter
OnCollisionEnter not getting calle!
Hello, I'm working on a racing game, and the car has a collider as a child, I'm also using the collider to detect if the car is moving the way
The collider responds well to all objects, however, it doesn't call the OnCollisionEnter function in the script attached to it.
but if the script is attached to another object that the car collides with, the function gets called A picture that may contain important information : http://img836.imageshack.us/img836/9937/g1px.png
Here is the script
var wrongWay : boolean = false;
static var previousCheckpoint : int;
function OnCollisionEnter (other : Collision) {
Debug.LogError("colldied");
if (other.gameObject.name == "WWCheckpoint 01")
{
if (previousCheckpoint == 0 || previousCheckpoint == 10)
{
wrongWay = false;
previousCheckpoint = 1;
}
else
{
wrongWay = true;
}
}
if (other.gameObject.name == "WWCheckpoint 02")
{
if (previousCheckpoint == 1)
{
wrongWay = false;
previousCheckpoint = 2;
}
else
{
wrongWay = true;
}
}
if (other.gameObject.name == "WWCheckpoint 03")
{
if (previousCheckpoint == 2)
{
wrongWay = false;
previousCheckpoint = 3;
}
else
{
wrongWay = true;
}
}
if (other.gameObject.name == "WWCheckpoint 04")
{
if (previousCheckpoint == 3)
{
wrongWay = false;
previousCheckpoint = 4;
}
else
{
wrongWay = true;
}
}
if (other.gameObject.name == "WWCheckpoint 05")
{
if (previousCheckpoint == 4)
{
wrongWay = false;
previousCheckpoint = 5;
}
else
{
wrongWay = true;
}
}
if (other.gameObject.name == "WWCheckpoint 06")
{
if (previousCheckpoint == 5)
{
wrongWay = false;
previousCheckpoint = 6;
}
else
{
wrongWay = true;
}
}
if (other.gameObject.name == "WWCheckpoint 07")
{
if (previousCheckpoint == 6)
{
wrongWay = false;
previousCheckpoint = 7;
}
else
{
wrongWay = true;
}
}
if (other.gameObject.name == "WWCheckpoint 08")
{
if (previousCheckpoint == 7)
{
wrongWay = false;
previousCheckpoint = 8;
}
else
{
wrongWay = true;
}
}
if (other.gameObject.name == "WWCheckpoint 09")
{
if (previousCheckpoint == 8)
{
wrongWay = false;
previousCheckpoint = 9;
}
else
{
wrongWay = true;
}
}
if (other.gameObject.name == "WWCheckpoint 10")
{
if (previousCheckpoint == 9)
{
wrongWay = false;
previousCheckpoint = 10;
}
else
{
wrongWay = true;
}
}
if (other.gameObject.name == "WWCheckpoint 11")
{
if (previousCheckpoint == 10)
{
wrongWay = false;
previousCheckpoint = 11;
}
else
{
wrongWay = true;
}
}
if (other.gameObject.name == "WWCheckpoint 12")
{
if (previousCheckpoint == 11)
{
wrongWay = false;
previousCheckpoint = 12;
}
else
{
wrongWay = true;
}
}
}
function Update() {
//Debug.LogError(previousCheckpoint);
}
Comment
Answer by $$anonymous$$ · Aug 12, 2013 at 01:39 PM
Note that collision events are only sent if one of the colliders also has a non-kinematic rigid body attached.
http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnCollisionEnter.html