import bpy
import math
from mathutils import Vector
from math import radians
# Create collection
zion_collection_name = "cone"
col = bpy.data.collections.new(zion_collection_name)
bpy.context.scene.collection.children.link(col)
# Set target location
target_location = Vector((-600, 0, 30)) # heiko idou taksa
# Set initial location
initial_locations = [Vector((0, 0, 30))]
# Set cone properties
cone_radius = 60
cone_depth = 60
# Calculate speeds based on initial distances
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 cone objects and set locations
for i, initial_location in enumerate(initial_locations):
bpy.ops.mesh.primitive_cone_add(radius1=cone_radius, radius2=0, depth=cone_depth)
cone = bpy.context.object
cone.location = initial_location
cone.name = "cone"
# Rotate cone by 180 degrees around the x-axis
cone.rotation_euler.rotate_axis('X', radians(0))
# 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(speeds[i], distance)
cone.keyframe_insert(data_path="location", frame=frame)
# Set the number of frames
def set_frame_range(start_frame, end_frame):
bpy.context.scene.frame_start = start_frame
bpy.context.scene.frame_end = end_frame
# Example: set the number of frames to 1000
set_frame_range(1, 1000)