0
$\begingroup$

I want camera to be rotated around y-axis, for an object placed at centre. Its rotating around z and x-axis, but not y-axis. I am attaching the code snippet.

import bpy
import math

scene = bpy.context.scene
context = bpy.context

cam = scene.objects['Camera']
cam.location = (0, 1, 0.6)
cam.data.lens = 35
cam.data.sensor_width = 32

cam_constraint = cam.constraints.new(type='TRACK_TO')
cam_constraint.track_axis = 'TRACK_NEGATIVE_Z'
cam_constraint.up_axis = 'UP_Y'

cam_empty = bpy.data.objects.new("Empty", None)
cam_empty.location = (0, 0, 0)
cam.parent = cam_empty

scene.collection.objects.link(cam_empty)
context.view_layer.objects.active = cam_empty
cam_constraint.target = cam_empty

stepsize = 30
cam_empty.rotation_euler[2] += math.radians(stepsize)

As per my understanding, "rotation_euler[2]" makes the camera rotate around z-axis. When I replace "[2]" with "[0]", the camera rotates around x-axis. But if I replace it with "[1]", the camera does not rotate.

$\endgroup$

1 Answer 1

0
$\begingroup$

screeenshot

I don't know what you are trying to do, but I tested it here and the camera did rotate on the Y axis (that I tried to draw on the screenshot). I changed the code a bit so it doesn't create an empty everytime. What I can guess is that you're having problems with gimbal lock, which only occurs with Euler angles. But yeah, that's the only clue I can give you. If you tell us what you're trying to do, that would help us to help up better.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .