- Home /
Collision Handling for a Fighting Game
Hey everyone!
I am currently developing an AI demo for a fighting game.
I wrote an OnTriggerEnter
function that detects fists or kicks; however it detecs actions if and only if the character move.
For example, I kick the other character, and my character's leg enters, and exits the collider but, OnTriggerEnter
is not called in this scenario until I move my character.
How can I solve this problem?
Thank you!
Here is my code:
function OnTriggerEnter(collision : Collider)
{
if( collision.gameObject.name == "AI_Arm" || collision.gameObject.name == "AI_Leg" )
{
Debug.Log("PLAYER HIT!");
}
}
P.S: I used other version of the "`OnTrigger`"s but, it remains same.
Answer by Danmietz · Jan 31, 2013 at 04:07 AM
You might want to have a read over this article. In short, for the sake of optimisation rigidbodies that aren't moving are considered "sleeping", which helps performance however it can result in problems like this.
In order to avoid it, you can force your rigidbody to stay awake with
rigidbody.WakeUp();
Hopefully that fixes the problem
It halped me to understand what is the real problem; however, rigidbody.WakeUp();
does not solve the problem.
Thank you.
By the way, I added Wakeup()
function to both game objects' update function and problem remains same.
Your answer
Follow this Question
Related Questions
Trigger Spawning? 1 Answer
OnTriggerEnter - Explosions that appear on the surface of hit object 1 Answer
how do i correctly use a box collider 1 Answer
OnTriggerEnter only working twice... 0 Answers
Keep doing something while colliding 1 Answer