- Home /

# How to calculate a following camera with a restrain angle

Hello I have a math related problem I can't seem to resolve, I am trying to create a tps camera in unity in 3D similar to what we can see in Diablo3 or the latest Minecraft Dungeon, I never did that so I made a drawing to see how I can program that.

I have multiple constraints :

My camera angle on the y axis should be 45°

My camera angle on the x axis is a fixed variable

The distance from my camera to the targeted object (character) is a fixed variable

Here's my drawing :

To tacle this problem I then need to find the position of the camera, I must use Thalès theorem

To find y I think I just need to multiply the cosinus of the angle (here 70°) by the hypotenuse which is the length of my fixed variable (here it's 3)

However to find x and z I think I first have to find the hypotenuse of those two light grey triangles, it's suppose to be the sinus of the angle (70) by the distance (3)

Now I can get x and z with those operations : x = sin(45) * hypotenuse of the light grey triangle and z = cos(45) * hypotenuse of the light grey triangle

Here is my code

The thing is I get something completely off center and I don't know why, I think my thinking is correct and my code as well

### 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.