- Home /
strange behavior on collision
Hello, I use this script to chop some trees
var Hardnes = 5;
var damage = 1;
var time :float;// ("is time");
function OnTriggerEnter (coll : Collider)
{
if(coll.gameObject.tag == "axe")
{
Hardnes -= damage;
Debug.Log ("CHOP");
if(Hardnes == 0)
{
Slice();
}
}
}
function Slice(){
gameObject.AddComponent ("Rigidbody");
Debug.Log ("slice column");
collider.isTrigger = false;
yield WaitForSeconds (time);
rigidbody.isKinematic = true;
}
if I give 1 hardnes at 4 tree object all go good
if I give 2 or more of hardness and chop 1 object. the other dosen't work, seem random collision detection
but if I hit the object in sequence, 1 hit to the 1° - 1 hit to the 2°- 1 hit to the 3°- object then restart, all work
do you know why, and how avoid this
thanks in advance
Answer by ScroodgeM · Aug 02, 2012 at 06:33 PM
probably you don't move away 'axe' object after collider enter. OnTriggerEnter() method called every time collider enters trigger, but between enters it should exit.
add OnTriggerExit() method with Debug.Log() to check this. if you are not exiting - that's a problem
it's happened though I move from an object to another and certainly I exit the collider the debug have the same result
hmm... i lost thread a little 8)
does 'axe' exiting from trigger between hits? does OnTriggerExit() calls after hit happened?
I don't use OnTriggerExit, try to add it with a Debulog
and do a video maybe explain better to me
do a video??? 8))))
function OnTriggerExit(coll : Collider) { Debug.Log ("obj with tag " + coll.gameObject.tag + " is exited"); }
add this near with OnTriggerEnter method. it should log for trigger-exiting events. check that axe exited it before next chop.
just to demonstrate how not work, it's go only if jump from one to another, sorry bad quality
I'm almost to surrender, too much bug on collision
Your answer
Follow this Question
Related Questions
Destroy(other.gameObject) isn't destroying parent, only children 2 Answers
Compound collider does not trigger the parent 1 Answer
get only one colliding body 3 Answers
Plane flyby triggering/help 1 Answer
Animation with frozen player ?? 0 Answers