- 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
Follow this Question
Related Questions
How to scale/calculate GameObject Z distance to the real physical world... 0 Answers
Find closest point to player input within 2D shape defined by lines/curves 2 Answers
Grab'n drag camera? (or, a little geometry problem) 2 Answers
Second Camera Position on Viewport to UI Element Position on Screen 2 Answers
2D Raycast in any direction 1 Answer