# 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

My answer wasn't totaly correct so i redo it : If your enemy and your player are looking in the same direction and your player hit the enemy, then he must be in his back. You can so do the project of the two forward (Vector3.Project(enemy.transform.forward, player.transform.forward), and what interest us is the z value: if it is 1, the player and the enemy are strictly looking in the same direction. if it > 0.5f, they are looking at the same direction with a margin of 45° if it is 0, they are looking in perpendicular directions if it is -1, the are looking in opposite directions.

So you can do something like : if(Vector3.Project(enemy.transform.forward, player.transform.forward).z>0.3f) CriticalHit();

**Answer** by ScaniX
·
Aug 26, 2016 at 01:13 PM

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. ;)

thanks I'm still experimenting with what you posted since I have an Isometric view.

Just change the `Vector3 angle`

to `float angle`

**Answer** by DavidWatts
·
Aug 26, 2016 at 01:16 PM

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.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

how to calculate the angle between two vectors? 6 Answers

hi everyone how can i move an object from a point to specific point(point b) by mouse click 0 Answers

How do I get the world coordinates of the top left position of the camera? 2 Answers

Get angle of two Vector3s 1 Answer

Is there a way to Destroy a GameObject with given Coordinates? 2 Answers