- Home /
OnTriggerEnter detection too late
Hello guys, I am with a problem that I have no idea how to solve elegantly. Well, my game has a character that can dash like an arrow. My idea is to let the enemies have a trigger area where you can dash and kill them. See the next figure:
The problematic enemy is this wallPin. It has three colliders, the body collider(normal), one in the point to kill the player(trigger) and another in the head where you can dash and kill it(trigger). These colliders are attached to the armature, following the "digging" animation in the pics 1 and 2. If the player is dashing and collides with something with a normal with an angle 180, the dash ends, and the problem is... In the picture the player rebounces at high speed ( app. 40 units of speed following Lerpz 2d engine ) between the 2 white cubes and goes up in the direction of the head, following the blue line. Then the collision detection first detects the collision with the pin's body, cancelling the dash, and after it sends the head's trigger enter message. With this late message, the player is not more dashing and the enemy won't die. The trigger detection code to kill enemies is:
function OnTriggerEnter (other : Collider)
{
Debug.Log( other.name + Time.time );
var platformerController : PlatformerController = other.gameObject.GetComponent( PlatformerController );
if( platformerController && platformerController.isDashing() )
{
enemyLife.getHit();
}
else if( platformerController && !platformerController.isDashing() )
{
Debug.Log( platformerController.isDashing() + other.name + Time.time );
}
}
So with someone knows how to make the trigger detection more precise or faster, please help me, I tried to put rigidbodies, change the square for a circle, put a rigidBody on the player, etc.
Ahhh, if I dash perpendicularly to the pin, hitting the head following the yellow line, it works well, because there is not a collider in the other side of the trigger.
Your answer
Follow this Question
Related Questions
I'd like some help with my health / shooting (collision detection) 1 Answer
2D Triggers and Collisions not working as expected. 2 Answers
How to handle animation of multiple Coins? 1 Answer
Detect when a trigger has entered a collider 1 Answer
Collision Detection - Strange issues! Working when it shouldnt, not working when it should! 2 Answers