I have a first person player, and there’s shooting using raycast and I wanted to detect/locate where i got hit with the raycast like in the front or back. Im gonna make a damage indicator to know where i got hit. how do i do this?
If you want to know if you hit the player in the back, as opposed to the front, then you would probably want to have two different colliders on the player, one for the fron and then one for the back.
Helpful
Devoted
then you can use the collision.normal to figure that out.
void ONCollisionEnter(Collision col){
// col.transform.position gives you the position in world space where you hit.
// col.gameObject gives you the gameObject you hit
//to figure out the contact points themselves (I think across multiple colliders)...
foreach (ContactPoint contact in collision.contacts) {
print(contact.thisCollider.name + " hit " + contact.otherCollider.name);
Debug.DrawRay(contact.point, contact.normal, Color.white);
}
}