Hey guys,
I’m trying to build a damage handling system for my spaceship game, and I need a way of determining what part of the ship is getting hit. I was hoping to do it by getting the specific point of the collision. Here is the relevant portion of my code so far:
private void OnCollisionEnter2D(Collision2D coll)
{
foreach (ContactPoint2D missileHit in coll.contacts)
{
Vector2 hitPoint = missileHit.point;
Debug.Log(hitPoint.x + " and " + hitPoint.y);
}
}
Now the coordinates this is returning are in world space, which isn’t very useful to me, as the spaceship is never just going to be sitting at the origin point of the scene.
So is there a way for me to get this information in a way that is RELATIVE to the collider? That way I could, for example, determine that if the Y value is negative, then I know the rear half of the ship has been hit, or if it’s positive, then the front half of the ship has been hit, etc.