import bpy
from mathutils import Vector
# Set target location
target_location = Vector((0, 0, 60))
# Set initial location
initial_location = Vector((0, 0, -30))
# Set cone properties
cone_radius = 60
cone_height = 60
# 初期位置との距離から速度を計算する
chousei_kijyun = 30
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 cone object and set location
bpy.ops.mesh.primitive_cone_add(radius1=0, radius2=cone_radius, depth=cone_height)
cone = bpy.context.object
cone.location = initial_location
# Set animation keyframes
last_frame = 600
for frame in range(last_frame+1):
distance = (target_location - cone.location).length
if distance > 0.01:
direction = (target_location - cone.location).normalized()
cone.location += direction * min(0.1, distance)
cone.keyframe_insert(data_path="location", frame=frame)