Object Rotation Problem

I am trying to create a simple ball shooter game, the cylinder which is acting as a gun can be rotated about the local x and z axis to fire up/down and left/right. The problem comes when you combine several rotations, you end up looking at the world at a very odd angle. I tried locking the y rotation but this didn’t help.

Is there a way of panning up/down and left/right without ending up at an odd angle to the horizon?

ballshooter.blend (571 KB)

(up, down, left and right arrows to pan, spacebar to shoot)

Thank you,

I couldn’t tell from what was shown, but is the cannon itself centered in a way where it can rotate with the floor? I ask, because the area where the cannon’s center is will change how it rotates on the Y axis in relation to the ground.

I’m not sure I get what you mean. It begins parallel to the floor with the local co-ordinates aligned with the global co-ordinates, so yes, when you initially rotate about the z axis it remains parallel to the floor. Its when you combine a rotation about the z axis with a rotation about the x axis that I get the unwanted rotation about the y axis.

I’ve partially fixed it by adding additional controls to rotate about the y axis, this means that you can get it back upright, is there a way of doing this automatically?

I also tried using a “track to” actuator with an empty above the gun but this prevented the motion actuators working.

Any ideas would be greatly appreciated.

Thank you,

This is because the Motion actuator performs the rotation in an order. I think it is X,Y,Z.

Edit: Removed a suggestion. Reason … it does not work as expected.

You can parent your object to empties that perform the rotation in the order you need.

rotate aroundZ
L__ rotate aroundX
. . . . L__ your object

This is quite a good method to keep the up-vector constant.

Could you maybe explain this in more detail or point me in the direction of a tutorial, I’ve tried with three parented empties, one for the z rotation, one for the x rotation and another above the cylinder with a TrackTo actuator applied to the cylinder to keep it pointing at the empty. Unfortunately the cylinder wouldn’t move at all with this setup.

I’m a bit stuck :frowning:


Azimuth rotation should be around global axis, while elevation should remain local. So I suggest you deselect the “L” options of the actuators driven by right/left arrows.

Need a quick demo?

check this one …

arrow keys + <Q>+<E> :wink:

you do not need such bombastic meshes. Empties will do the trick as well :evilgrin:


AdditiveRotationDemo.blend (86.3 KB)

The example was very clear and I’ve implemented it without any trouble.

Thank you again,