Finding contact point in OnTriggerEnter2D?
Is there a way to do this? If the colliders are not triggers they will end up pushing each other around which is not what I want. Another suggestion I've heard is using kinematic rigid body but that doesn't fix the issue entirely.
Here is my current code:
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "PlayerDamage")
{
int result = ps.attack - def;
if (result <= 0)
{
result = 1;
}
hp -= result;
print(gameObject.name + " took " + result + " damage");
ContactPoint2D[] contacts = new ContactPoint2D[1];
other.GetContacts(contacts);
Vector3 effect_pos = contacts[0].normal;
//Vector3 effect_pos = new Vector3(transform.position.x, transform.position.y, transform.position.z);
Quaternion effect_rot = new Quaternion(0, 0, 0, 0);
if (hp <= 0)
{
Instantiate(death_effect, effect_pos, effect_rot);
Destroy(gameObject);
}
else
{
Instantiate(damage_effect, effect_pos, effect_rot);
}
}
}
Comment