import bpy
import math
from mathutils import Vector
# Set target location
target_location = Vector((0, 0, 30))
# Set initial locations
initial_locations = [ Vector((0, 0, -34))]
# Set torus properties
torus_major_radius = 60
torus_minor_radius = 2
# 初期位置との距離から速度を計算する
chousei_kijyun = 60
distances = [math.sqrt(sum([(a - b) ** 2 for a, b in zip(loc, target_location)])) for loc in initial_locations]
speeds = [0.1 * distance / chousei_kijyun if distance > 0 else 0 for distance in distances]
# Create torus objects and set locations
for i, initial_location in enumerate(initial_locations):
bpy.ops.mesh.primitive_torus_add(major_radius=torus_major_radius, minor_radius=torus_minor_radius)
torus = bpy.context.object
torus.location = initial_location
torus = bpy.context.object
torus.name = "torus 追いつかない"
# Set animation keyframes
last_frame = 600
for frame in range(last_frame+1):
distance = (target_location - torus.location).length
if distance > 0.01:
direction = (target_location - torus.location).normalized()
torus.location += direction * min(speeds[i], distance)
torus.keyframe_insert(data_path="location", frame=frame)
import bpy
# フレーム数を変更するための関数
def set_frame_range(start_frame, end_frame):
bpy.context.scene.frame_start = start_frame
bpy.context.scene.frame_end = end_frame
# 例: フレーム数を100に変更する場合
set_frame_range(1, 1000)