- Home /
Checking to see if two objects are colliding.
When I destroy an enemy, it drops a health box meant to restore the health of a player. I am trying to get it to where if the player comes in contact with the health box, the box gets destroyed. this is the code I have so far but it doesn't seem to be updating because I'm not getting the log in my console.
var healthDrop : Transform;
function OnCollisionEnter (col : Collision)
{
Debug.Log("activated");
if (col.collider.tag == "healthDrop")
{
Destroy(healthDrop);
}
}
Is your player using the default CharacterController, without other rigidbodies or colliders? $$anonymous$$ake sure your "collision" meets the criteria. You might use OnTriggerEnter ins$$anonymous$$d.
http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html
It is the default CharacterController, I did try OnTriggerEnter as well with the same results.
Answer by getyour411 · Jan 28, 2014 at 01:52 AM
Review CharacterController
I read over that a couple of times not getting any new information that would help me. Does my box need to have a RigidBody?
Edit: Added a rigid body to both objects and re-tried OnTriggerEnter but to no avail.
This actually did help! sorry for being stupid haha!
Test empty scene: First Person Controller w/ default Character Controller. Attached to player:
void OnTriggerEnter (Collider col) { Debug.Log("activated");
Cube placed in scene is marked 'AsTrigger' Hit Play, drive CC into cube "activated" in debug.log Please review.
Answer by Stash329 · Jan 28, 2014 at 03:34 AM
I honestly can't see anything wrong with this. Try adding something to it for example :
var Collider = false;
var HealthDrop : Transform;
function OnTriggerEnter(){
Collider = true;
}
Function update(){
If ( Collider == true ){
Debug.Log("Activated");
Destroy(HealthDrop);
}
}
I'm guessing nor hoping that this would work or give you an idea. Hope this helped ! And good luck :)
Your answer
Follow this Question
Related Questions
How can I make my truck drive on terrain and on bridge 1 Answer
OnCollisionEnter Collision not detected? 1 Answer
Player take damage on collision with AI 1 Answer
Character controller mess up damage 3 Answers
OnCollisionEnter Problem 1 Answer