Copying Object Y-rotation to other object

Hi,

I have one actor which can be rotated. Now I am trying to copy the Y-rotation for the actor to the empty I have. What is the best way doing this in BGE ?

I have tested making constraints in animation side, which makes the Y-axis to be copied from the actor object to the empty. This works fine in 3D view and in animation side but in BGE it doesn’t.

I have tested the python to do something like this. Any suggestions to the “No idea what to put here” string :slight_smile: ?

  import GameLogic as g
  empty = g.getCurrentcontroller().getOwner()
  ship = g.getCurrentScene().getObjectList()["OBShip"]
  eori = empty.getOrientation()
  sori = ship.getOrientation()
  
  eori.setOrientation( No idea what to put here )


Thanks for help,
-Mika

Hello,

I thought that I found the answer but I forgot that I only want to copy the Y-Rotation. So still trying to make the correct setOrientation parameter here.


  eori.setOrientation(sori)

But if there is some logic brick / better way to do this, I would be really interested in hearing it :slight_smile:

Thanks again,
-Mika

Hi,

Found the correct code to calculate the Rotation along Z-axis. Which was actually what I was looking for :slight_smile:


import GameLogic as g 
 
ship = g.getCurrentScene().getObjectList()["OBCube"] 
empty = g.getCurrentController().getOwner() 
 
sori = ship.getOrientation() 
eori = empty.getOrientation() 
 
nori = eori 
nori[0][0] = sori[0][0] 
nori[1][1] = sori[1][1] 
nori[0][1] = sori[0][1] 
nori[1][0] = sori[1][0] 
 
empty.setOrientation(nori)

Hello,

Doh ! It didn’t work after all. Other rotations effect still :frowning:

-Mika

Hi,

And the final maths could be something like this. Thanks to blenderartists forums.


import GameLogic as g
import math

def mat2euler_rot(mat):
    mtx = 
[list(mat[0][:3]), list(mat[1][:3]), list(mat[2][:3])]
    angle_y = - math.asin(max(min(mtx[0][2], 1.0), -1.0))
    C = math.cos(angle_y)
    if C != 0.0:
        C = 1.0/C
    angle_x = math.atan2(mtx[1][2] * C, mtx[2][2] * C)
    angle_z = math.atan2(mtx[0][1] * C, mtx[0][0] * C)
    return (angle_x, angle_y, angle_z)

empty = g.getCurrentController().getOwner()
ship = g.getCurrentScene().getObjectList()["OBShip"]

eori = empty.getOrientation()
sori = ship.getOrientation()

angle_z = mat2euler_rot(sori)[2];
cos = math.cos(angle_z)
sin = math.sin(angle_z)
nori = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
nori[0][0] = cos
nori[1][1] = cos
nori[0][1] = -sin
nori[1][0] = sin

empty.setOrientation(nori)