- Home /
Problem with collision detection
I am making a simple game where you shoot a fireball at a sphere monster that follows you. My code for the collision and the monster's following is this:
var thing : Transform;
var speed : float = 3.0;
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "Fireball")
{
Debug.Log("hit");
transform.Destroy(gameObject);
}
}
function Update ()
{
transform.LookAt(thing);
transform.Translate(Vector3.forward * (speed * Time.deltaTime));
}
it doesn't destroy the monster and it doesn't say hit when i play the game and shoot at the monster. I made sure everything that needs it has colliders and everything else works (except for the fact that the monster goes through the terrain's hills)
Answer by qJake · May 21, 2010 at 10:05 PM
Why are you using "OnControllerColliderHit"? From the documentation:
OnControllerColliderHit is called when the controller hits a collider while performing a Move.
You need to change that to either OnColliderEnter(Collision hit)
or OnTriggerEnter(Collider hit)
depending on how you have your game set up.
If this answer worked for you, please consider upvoting (click the Up arrow), and accepting the answer (click the outline of the check mark). Thanks.
Your answer
Follow this Question
Related Questions
raycast hit point is wrong 2 Answers
Camera looking through objects when touching 1 Answer
get angular velocity change from collision 0 Answers
No OnCollisionEnter with 2D colliders? 1 Answer
How do I increase speed after collision? 2 Answers