how can i determine the back of object?

i want to make something like a backstab, it means when i am behind some object, i can deal more damage.
any help would be appreciated

If “other” is the enemy gameObject, you can calculate the angle between the enemies forward vector and the delta vector. Comparing just the both forward vectors would not actually say anything about your position relative to the enemy. You will have the same angle if you are standing right in front of or behind the enemy.

Vector3 delta = transform.position - other.transform.position;
Vector3 angle = Vector3.Angle(other.transform.forward, delta);
float backstabbiness = Mathf.Abs(angle) / 180f; // Mathf.Abs() is probably not necessary

The closer the angle gets to 180° the closer you are to be directly behind him. A backstabbiness value of > 0.7f should take him out instantly. :wink:

you can take the dot product between the enemies forward vector and a position in space. if the dot product is greater than 0 then the position is in front and if its less than 0 then its behind.