If cube1 has rotation logic, how can I make cube2 imitate the rotation of cube1 without using the logic of cube 1?

  • $\begingroup$ just for any of you one-liners out there, copy rotation constraint does not work in GE. $\endgroup$ – Scalia Jun 26 '15 at 21:58

This is possible with a simple python script:

import bge

def main():
    scene = bge.logic.getCurrentScene()

    cube1 = scene.objects["realCube"]
    cube2 = scene.objects["secondCube"]

    cube2.worldOrientation = cube1.worldOrientation

where realCube and secondCube are the names of the actual cube objects in blender.

enter image description here

To attach this script to secondCube, you can use a python controller with an always sensor. Note that the script name must end in a .py extension for the script to be recognized as a module, and that the python controller is given a method (.main) defined as a function inside the script:

enter image description here


One way is to use drivers. You can, in effect, link the properties of one object to other objects. In your example, you have the choice of driving all 3 rotation angles or just a single angle.

To add a driver, display the rotation properties of the linked-to object (cube2 in your example). An easy way to do this is press "N" in the 3D View or choose the Object Properties tab. Then right-click one of the rotation angle values. Choose "Add Drivers" (all 3 rotations) or "Add Single Driver" (only the chosen rotation). The property value will turn purple and can no longer be changed manually. You can remove the driver by right-clicking and choosing again.

Next open a Graph Editor window and press "N" to display the Properties sidebar. To the right of the window menu ('View', 'Select', 'Marker', 'Channel', 'Key'), there is a drop-down labeled "F-Curves". Change this to "Drivers".

For simplicity sake, I'll describe how to set up one driven rotation angle. If you want to drive 2 or 3 rotation angles, simple repeat the following steps:

  1. In the upper left, click one of the angles below "Drivers". If they aren't visible, you may need to click "Drivers". Find the Drivers panel in the right-hand Properties sidebar. This panel shows the driver setup.

  2. The first item you likely want to change is "Scripted Expression" to either "Averaged Value" or "Sum Values". Since you want to copy a single property, you will get the property you want by choosing the average or sum of that single value. (This was confusing to me at first, but it provides a lot of power and flexibility in more complex situations.)

  3. By default, a variable has been created called "var". Choose the driving object (cube1 in your example) and then choose the property you want to copy using the "Type" drop-down menu.

  4. You might click "Update Dependencies" if an error message appears beneath the "Remove Driver" button.

You can test out the driver by rotating cube1 and watch cube2.

Other resources on using drivers:

  • 1
    $\begingroup$ AFAIK drivers don't work in the BGE either.. $\endgroup$ – gandalf3 Jun 26 '15 at 23:36
  • $\begingroup$ You're right, gandalf3. You can set up the driver. It just won't operate in Play mode. I didn't check. $\endgroup$ – astrogeek Jun 27 '15 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.