- Home /
Collider2D Collision Offset
I am using ForceMode2D.Impulse when the player jumps. (The player is the triangle)
void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Player")
{
other.GetComponent<PlayerBase>().Die();
}
}
This is the code I am using to detect when the player touches the spikes (the two triangles)
For some reason, even though the colliders do not touch, OnTriggerEnter2D is still called.
Here are my Physics2D settings:
EDIT: If I use OnTriggerStay2D, it suddenly works. Can anyone give insight into why this is?
Thanks for any help!
The spikes.
I am at a complete loss as to why this is happening :(
You could try reducing the penetration for penalty value. $$anonymous$$aybe that'd push your character away from the spikes before hitting the spikes. Edit > Project settings > Physics
http://docs.unity3d.com/$$anonymous$$anual/class-Physics$$anonymous$$anager.html
I have tried all that. It doesn't matter how low or high I set the penetration for penalty value, it still triggers. I have no idea what else can be going on. =(
How can the collider on the player be penetrating that deep past the BoxCollider2D?
Rigid bodies (if that's what you are using), have a few options on how to do collision: discrete, continuous, continuous dynamic
I would play around with those, and see if one of those options prevents the OnTriggerEnter from being called early.
Another thought: It appears that OnTriggerEnter is being called the cycle before the impact. I suspect this is because the impact would occur (given the velocities of the objects), just BEFORE the next cycle would come around (but after the current cycle). This is just a program$$anonymous$$g choice Unity made: Do we call OnTriggerEnter once the objects are overlapping, or just before they are overlapping? If you think about it a bit, you can figure out why they chose the "before they are overlapping" option.