Why is this script not working? (80655)

In this question I was given part of a script and told to attach it to my player. There are no errors, but the script doesn’t seem to do anything. Here it is:

var DeathSpeed : int; 

function Update(){

}

function OnCollisionEnter(collision : Collision)
{
if(collider.relativeVelocity.magnitude > DeathSpeed)// where "someValue" is a variable of your choosing.
{
Debug.Log("DEAD");// You'll have to implement how the player will die, yourself, but just call the function(s) needed to kill them, here.
}
}

Can anyone help?

Print out the condition and see if it ever returns true. The logic may not be what you desire. To print out the "DEAD" your object will need to have a velocity greater than DeathSpeed and at the same time have a collision with this object.

–

I tried all of the suggestions so far, but to no avail. If anyone else wants to offer a suggestion that'd be great.

–

2 Answers

2

Change if(collider…) to if(collision…)

http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnCollisionEnter.html

I've done this, but I still can't seem to get it to work.

–

Does one of the objects have a rigidbody attached to it? As OnCollisionEnter requires it.

The boxes that aren't the player have rigidbodies, so that can't be the problem I think. Hmmm...

–