character collision question

I have random blocks constantly coming towards the character and trying to set up something so when the blocks hit the character, character dies.

function OnControllerColliderHit(hit : ControllerColliderHit)
{
    if(hit.gameObject.tag == "blocks")
    {
        dead = true;
        HealthControl.LIVES -= 1;
    }

}

For some reason, this only works when the character is moving. When the character stays still, and the block hits it, nothing happens.

Any ideas? Thanks in advance.

1 Answer

1

Quoting the OnControllerColliderHit documentation:

OnControllerColliderHit is called when the controller hits a collider while performing a Move.

You might need to flip your logic, and put the script on the moving blocks.

The cubes would still have to send the message via collision logic though, I think thats what Marowi is referring to (he needs to flip the collision logic onto the cubes and not the player).