 # Need help randomly rotating plane

I would like to rotate a plane 90 degrees so it stays vertical & then randomize the z axis rotation with a slight rotation of the x and y as well, just need it to stay vertical.

I have tried this, but zero luck, open to any suggestions:

``````
bpy.ops.transform.rotate(value=1.5708, orient_axis='X', orient_type='LOCAL', orient_matrix=((-0.833314, 0.552801, -1.07288e-06), (-0.290321, -0.437639, 0.850991), (0.470428, 0.709143, 0.52518)), orient_matrix_type='VIEW', constraint_axis=(True, False, False), mirror=True, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)

random.seed(random.random())
z = random.randint(-100,100)

plane.rotation_mode = 'XYZ'
plane.rotation_euler = (0,0,z)

``````

example : Using a handler . . . .

``````import bpy, random

def set_rnd():
random.seed(random.random())
plane = bpy.data.objects.get("Plane")
z = random.randint(-100,100)
plane.rotation_mode = 'XYZ'
plane.rotation_euler = (0,0,z)

# every frame change, this function is called.
def my_handler(scene):
set_rnd()

bpy.app.handlers.frame_change_pre.append(my_handler)
``````
2 Likes

The thing is, it doesn’t keep the plane vertical, i’m not sure if I am doing something wrong.
You add a plane > Rotate it 90 degrees on the X axis > Scale it along the Z axis(value= 2) > & then randomly rotate it(z axis)

I am trying to convert those steps into python code, with the last step having different values, all while keeping the plane vertical(maybe a little X, Y offsets, not too much)

When I run it on my machine, it keeps it vertical. Therefore, something else is effecting it. Try it on a brand newly opened file, create a plane, then run the script. If you cannot think of anything else, you CAN lock the x and y axis.