# How do I get all 3 3d angles between 2 points in bge(2.78)?

I’ve done this several times before but for some reason can now not remember how to do this.

basically I know the positions of 2 points in 3d space (the locations of the objects) and want to get their (x,y,z) angles as they’d appear in the sidebar during the use of regular blender.

(bge 2.78)

``````object.worldOrientation = [angleX, angleY, angleZ] # to assign an orientation to an object
[angleX, angleY, angleZ] = object.worldOrientation.to_euler() # to retrieve the orientation of an object
``````

this is not what i asked for

i’m trying to retrieve the 3 angles x y z beween 2 different objects at different positions, i hope that is more clear.

vec_to = (pos_1 - pos_2).normalized()
distance = (pos_1 - pos_2).magnitude()

i have no idea what you’re trying to accomplish with this, my bge doesn’t come with a .normalized attribute, and that wouldn’t return any of the angles anyways.

you mean you want a compass that points at the target?

Use localOrientation instead of world and compare.

that’s much closer to what i want. but not quite.

if you imagine having point B as a face on the object
and point A as its center I’d like to know how to get the rotation of the object as is.

i’ve done this before so i know my version of bge is capable but i do not remember how I accomplished it.

I can no longer find the formula online or in my notes, this would be less appropriate but could possibly work as long as i’m still able to get the objects 3d rotation coordinates. Please give an example on how to do this.

``````
import bge
import math

scene = bge.logic.getCurrentScene()
obj = scene.objects['Cube.001']

print('-'*128)

#pi/2 - atan(x, y) giving z
print("RUN Z")
print(math.degrees(math.pi/2 - math.atan2(obj.worldPosition[0], obj.worldPosition[1]))-90)

#pi/2 - atan(x, z) giving x
print("RUN Y")
print((math.degrees(math.pi/2 - math.atan2(obj.worldPosition[0], obj.worldPosition[2]))-90)*-1)

#pi/2 - atan(y, x) giving y
print("RUN X")
print(math.degrees(math.pi/2 - math.atan2(obj.worldPosition[1], obj.worldPosition[2]))-90)
``````

(from centre)
solved. you can see why I couldn’t remember it in my head.

``````import bge
import math

scene = bge.logic.getCurrentScene()
obj = scene.objects['Cube.001']
centerobject = scene.objects['Cube.003']

print('-'*128)
cx=centerobject.worldPosition[0]
cy=centerobject.worldPosition[1]
cz=centerobject.worldPosition[2]

#pi/2 - atan(x, y) giving z
print("RUN Z")
print(math.degrees(math.pi/2 - math.atan2(obj.worldPosition[0]-cx, obj.worldPosition[1]-cy))-90)

#pi/2 - atan(x, z) giving x
print("RUN Y")
print((math.degrees(math.pi/2 - math.atan2(obj.worldPosition[0]-cx, obj.worldPosition[2]-cz))-90)*-1)

#pi/2 - atan(y, x) giving y
print("RUN X")
print(math.degrees(math.pi/2 - math.atan2(obj.worldPosition[1]-cy, obj.worldPosition[2]-cz))-90)
``````

(from 2 distinct points)