# calculating position with given params (1 Viewer)

#### SgtIgram

##### Newcomer
Howdy!
so since im restricted to realise it in Lua i post my problem here.
furthermore im restricted to some ingame limitations (game: stormworks) so i cant use any fancy libs.
i sounded so simple but drove me a bit crazy.

What i need:
the global(not relative to object A) 3D (x,y,z) position of an object (lets call it object B)

What i have:
i have the global position (x,y,z) of an object A.
i know the distance between object A and object B aswell as in which direction (heading and pitch/horizontal and vertikal) it is

i tried smashing the degrees converted with math.rad into math.cos/math.sin and multiply it with the distance.. but im not that experienced with that kind of stuff and it didnt worked. (i can manually check object Bs position and see if its somewhat close or far off)

thanks in advance and greetings
- sgtigram

#### mje

##### Newcomer
You are along the right line, but probably missing some details. There's lots of game programming math resources on line that should give you the exact formulas. Basically
dx = dist*sin(phi)*cos(theta)
dy = dist*sin(phi)*sin(theta)
dz = dist*cos(phi)