Skip to content

Instantly share code, notes, and snippets.

@hotohoto
Last active July 1, 2024 15:38
Show Gist options
  • Save hotohoto/1d37ce63bb3c3a0d7e37447c96ffdf9c to your computer and use it in GitHub Desktop.
Save hotohoto/1d37ce63bb3c3a0d7e37447c96ffdf9c to your computer and use it in GitHub Desktop.
Rotate an object by setting yaw pitch roll
import bpy
import mathutils
import math
# blender rotate in the right hand direction
figher = bpy.context.scene.objects['airplane']
figher.location = (0, 0, 0)
figher.rotation_euler = (0, 0, 0)
yaw = math.radians(190)
pitch = - math.radians(-50)
roll = math.radians(10)
matrix_yaw = mathutils.Matrix.Rotation(yaw, 4, 'Z')
matrix_pitch = mathutils.Matrix.Rotation(pitch, 4, 'Y')
matrix_roll = mathutils.Matrix.Rotation(roll, 4, 'X')
figher.rotation_euler = (matrix_yaw @ matrix_pitch @ matrix_roll).to_euler()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment