I need to rotate an object along arbitrary axis (local Z) in the range of 360 degrees. However, the rotate_axis method limits the angle value to 180 degrees and adds a sign (+/-) to allow for 360 degrees rotation. So if I need to animate a rotation of an object by more than 180 degrees it behaves in an undesired way (Animation 1).

This is the code from first animation: obj.rotation_euler.rotate_axis("Z", radians(40))

The second animation was made with manual input into rotation Z field.

What I'd like to achieve is shown in the second animation. I know it is sometimes difficult to come up with a solution without knowledge of what the end product should look like. The final effect is a cube that follows an animated path combined of multiple keyframes on a sphere. Like a car driving on the surface of the earth. (see below animations)

Animation 1

Animation 2

What I need to do is to rotate a cube (first picture below) so that its' local Z axis is aligned with a sphere normal (blue side up - second picture below), and its' local X axis is aligned with a line joining two visible plain axes (red side facing one of plains - third picture below). Now at the end ot this operations I need to have a 360 degrees data instead of +/-180 in order to avoid overrotation as shown in the first animation above.

Take a look at the animation at the end.

enter image description here

enter image description here

enter image description here

Here you can see what I am dealing with. When rotation around Z skips the 180 the cube is overrotating.

enter image description here

  • $\begingroup$ Possibly related: blender.stackexchange.com/a/215778/60486 $\endgroup$ May 31, 2021 at 14:49
  • $\begingroup$ What if the cube is at a place on the sphere, where the normal of the sphere (and so the Z axis of the cube) points where the X axis of the cube is supposed to point as well? 🤔 i.imgur.com/K8SwAB9.png $\endgroup$ Jun 1, 2021 at 8:21
  • $\begingroup$ That is impossible. There are over 1000 cubes like this moving around the sphere using various paths. Moreover, the local X axis must always be perpendicular to normal, while the local Z must be always parallel to spheres’ normal. $\endgroup$
    – pilotnik
    Jun 1, 2021 at 8:35
  • $\begingroup$ Yes, it's impossible for a vector A to be parallel to a vector C and a vector B to be perpendicular to a vector A and parallel to a vector D if vectors C and D are parallel - because that would mean that vector B by being parallel to D is also parallel to vector C, and therefore parallel to vector A, and yet it's supposed to be perpendicular to vector A. So you need such a vector B that is both parallel and perpendicular to vector A. $\endgroup$ Jun 1, 2021 at 8:47

1 Answer 1


try this:

import bpy
import math

scene = bpy.data.scenes["Scene"]
mycube = bpy.data.objects['Cube']
mycube.rotation_mode = 'XYZ'

scene.frame_start = 1
scene.frame_end = 100

mycube.rotation_euler = (0, 0, 0)
mycube.keyframe_insert('rotation_euler', index=2 ,frame=1)
mycube.location = (0,0,0)
mycube.keyframe_insert('location', index=1, frame = 1)

mycube.rotation_euler = (0, 0, math.radians(360))
mycube.keyframe_insert('rotation_euler', index=2 ,frame=100)
mycube.location = (0,-13,0)
mycube.keyframe_insert('location', index=1, frame = 100 )



  • $\begingroup$ Yes. I am aware of this. That was one of my dead-ends as I need to rotate along arbitrary axis parallel to sphere normal. So still I need to find the euler rotation that I could pass to an object. $\endgroup$
    – pilotnik
    May 31, 2021 at 15:09
  • $\begingroup$ ok, then i don't understand what you want. maybe make a drawing what you want to have... $\endgroup$
    – Chris
    May 31, 2021 at 15:18
  • $\begingroup$ Have a look now. $\endgroup$
    – pilotnik
    May 31, 2021 at 23:39

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.