Skip to main content
edited body
Source Link
Gorgious
  • 31.8k
  • 2
  • 49
  • 106

You can spawn cameras in a circle around your object, at the altitude of your main camera. Then add a "Track to" constraint to make the camera face the target object. Finally, set the camera to active.

The constraint adds the benefit that it will follow the target object if it moves. If you dont have a target object you can create an empty in the scene.

How to randomly distribute points along a circle

import bpy
import math
import random
from mathutils import Vector

camera = bpy.data.objects['MainCamera']  # Make sure your first camera is named 'MainCamera'
target_object = bpy.data.objects['Cube']  # The camera will face this object. /!\ Naming

z = camera.location[2]
radius = Vector((camera.location[0], camera.location[1], 0)).length
angle = 2 * math.pi * random.random()

# Randomly place the camera on a circle around the object at the same height ofas the main camera
new_camera_pos = Vector((radius * math.cos(angle), radius * math.sin(angle), z))

bpy.ops.object.camera_add(enter_editmode=False, location=new_camera_pos)

# Add a new track to constraint and set it to track your object
track_to = bpy.context.object.constraints.new('TRACK_TO')
track_to.target = target_object
track_to.track_axis = 'TRACK_NEGATIVE_Z'
track_to.up_axis = 'UP_Y'

# Set the new camera as active
bpy.context.scene.camera = bpy.context.object

Result :

enter image description here

You can spawn cameras in a circle around your object, at the altitude of your main camera. Then add a "Track to" constraint to make the camera face the target object. Finally, set the camera to active.

The constraint adds the benefit that it will follow the target object if it moves. If you dont have a target object you can create an empty in the scene.

How to randomly distribute points along a circle

import bpy
import math
import random
from mathutils import Vector

camera = bpy.data.objects['MainCamera']  # Make sure your first camera is named 'MainCamera'
target_object = bpy.data.objects['Cube']  # The camera will face this object. /!\ Naming

z = camera.location[2]
radius = Vector((camera.location[0], camera.location[1], 0)).length
angle = 2 * math.pi * random.random()

# Randomly place the camera on a circle around the object at the same height of the main camera
new_camera_pos = Vector((radius * math.cos(angle), radius * math.sin(angle), z))

bpy.ops.object.camera_add(enter_editmode=False, location=new_camera_pos)

# Add a new track to constraint and set it to track your object
track_to = bpy.context.object.constraints.new('TRACK_TO')
track_to.target = target_object
track_to.track_axis = 'TRACK_NEGATIVE_Z'
track_to.up_axis = 'UP_Y'

# Set the new camera as active
bpy.context.scene.camera = bpy.context.object

Result :

enter image description here

You can spawn cameras in a circle around your object, at the altitude of your main camera. Then add a "Track to" constraint to make the camera face the target object. Finally, set the camera to active.

The constraint adds the benefit that it will follow the target object if it moves. If you dont have a target object you can create an empty in the scene.

How to randomly distribute points along a circle

import bpy
import math
import random
from mathutils import Vector

camera = bpy.data.objects['MainCamera']  # Make sure your first camera is named 'MainCamera'
target_object = bpy.data.objects['Cube']  # The camera will face this object. /!\ Naming

z = camera.location[2]
radius = Vector((camera.location[0], camera.location[1], 0)).length
angle = 2 * math.pi * random.random()

# Randomly place the camera on a circle around the object at the same height as the main camera
new_camera_pos = Vector((radius * math.cos(angle), radius * math.sin(angle), z))

bpy.ops.object.camera_add(enter_editmode=False, location=new_camera_pos)

# Add a new track to constraint and set it to track your object
track_to = bpy.context.object.constraints.new('TRACK_TO')
track_to.target = target_object
track_to.track_axis = 'TRACK_NEGATIVE_Z'
track_to.up_axis = 'UP_Y'

# Set the new camera as active
bpy.context.scene.camera = bpy.context.object

Result :

enter image description here

added 9 characters in body
Source Link
Gorgious
  • 31.8k
  • 2
  • 49
  • 106

You can spawn cameras in a circle around your object, at the altitude of your main camera. Then add a "Track to" constraint to make the camera face the cubetarget object. Finally, set the camera to active.

The constraint adds the benefit that it will follow the target object if it moves. If you dont have a target object you can create an empty in the scene.

How to randomly distribute points along a circle

import bpy
import math
import random
from mathutils import Vector

camera = bpy.data.objects['MainCamera']  # Make sure your first camera is named 'MainCamera'
target_object = bpy.data.objects['Cube']  # The camera will face this object. /!\ Naming

z = camera.location[2]
radius = Vector((camera.location[0], camera.location[1], 0)).length
angle = 2 * math.pi * random.random()

# Randomly place the camera on a circle around the object at the same height of the main camera
new_camera_pos = Vector((radius * math.cos(angle), radius * math.sin(angle), z))

bpy.ops.object.camera_add(enter_editmode=False, location=new_camera_pos)

# Add a new track to constraint and set it to track your object
track_to = bpy.context.object.constraints.new('TRACK_TO')
track_to.target = target_object
track_to.track_axis = 'TRACK_NEGATIVE_Z'
track_to.up_axis = 'UP_Y'

# Set the new camera as active
bpy.context.scene.camera = bpy.context.object

Result :

enter image description here

You can spawn cameras in a circle around your object, at the altitude of your main camera. Then add a "Track to" constraint to make the camera face the cube. Finally, set the camera to active.

The constraint adds the benefit that it will follow the target object if it moves. If you dont have a target object you can create an empty in the scene.

How to randomly distribute points along a circle

import bpy
import math
import random
from mathutils import Vector

camera = bpy.data.objects['MainCamera']  # Make sure your first camera is named 'MainCamera'
target_object = bpy.data.objects['Cube']  # The camera will face this object. /!\ Naming

z = camera.location[2]
radius = Vector((camera.location[0], camera.location[1], 0)).length
angle = 2 * math.pi * random.random()

# Randomly place the camera on a circle around the object at the same height of the main camera
new_camera_pos = Vector((radius * math.cos(angle), radius * math.sin(angle), z))

bpy.ops.object.camera_add(enter_editmode=False, location=new_camera_pos)

# Add a new track to constraint and set it to track your object
track_to = bpy.context.object.constraints.new('TRACK_TO')
track_to.target = target_object
track_to.track_axis = 'TRACK_NEGATIVE_Z'
track_to.up_axis = 'UP_Y'

# Set the new camera as active
bpy.context.scene.camera = bpy.context.object

Result :

enter image description here

You can spawn cameras in a circle around your object, at the altitude of your main camera. Then add a "Track to" constraint to make the camera face the target object. Finally, set the camera to active.

The constraint adds the benefit that it will follow the target object if it moves. If you dont have a target object you can create an empty in the scene.

How to randomly distribute points along a circle

import bpy
import math
import random
from mathutils import Vector

camera = bpy.data.objects['MainCamera']  # Make sure your first camera is named 'MainCamera'
target_object = bpy.data.objects['Cube']  # The camera will face this object. /!\ Naming

z = camera.location[2]
radius = Vector((camera.location[0], camera.location[1], 0)).length
angle = 2 * math.pi * random.random()

# Randomly place the camera on a circle around the object at the same height of the main camera
new_camera_pos = Vector((radius * math.cos(angle), radius * math.sin(angle), z))

bpy.ops.object.camera_add(enter_editmode=False, location=new_camera_pos)

# Add a new track to constraint and set it to track your object
track_to = bpy.context.object.constraints.new('TRACK_TO')
track_to.target = target_object
track_to.track_axis = 'TRACK_NEGATIVE_Z'
track_to.up_axis = 'UP_Y'

# Set the new camera as active
bpy.context.scene.camera = bpy.context.object

Result :

enter image description here

Source Link
Gorgious
  • 31.8k
  • 2
  • 49
  • 106

You can spawn cameras in a circle around your object, at the altitude of your main camera. Then add a "Track to" constraint to make the camera face the cube. Finally, set the camera to active.

The constraint adds the benefit that it will follow the target object if it moves. If you dont have a target object you can create an empty in the scene.

How to randomly distribute points along a circle

import bpy
import math
import random
from mathutils import Vector

camera = bpy.data.objects['MainCamera']  # Make sure your first camera is named 'MainCamera'
target_object = bpy.data.objects['Cube']  # The camera will face this object. /!\ Naming

z = camera.location[2]
radius = Vector((camera.location[0], camera.location[1], 0)).length
angle = 2 * math.pi * random.random()

# Randomly place the camera on a circle around the object at the same height of the main camera
new_camera_pos = Vector((radius * math.cos(angle), radius * math.sin(angle), z))

bpy.ops.object.camera_add(enter_editmode=False, location=new_camera_pos)

# Add a new track to constraint and set it to track your object
track_to = bpy.context.object.constraints.new('TRACK_TO')
track_to.target = target_object
track_to.track_axis = 'TRACK_NEGATIVE_Z'
track_to.up_axis = 'UP_Y'

# Set the new camera as active
bpy.context.scene.camera = bpy.context.object

Result :

enter image description here