2023年4月8日土曜日

Z軸 球体 速度制限 20230409 sun

 

import bpy

import math

zion_collection_name = "Sphere Z軸"

# コレクションを作成する

col = bpy.data.collections.new(zion_collection_name)

bpy.context.scene.collection.children.link(col)








import bpy

from mathutils import Vector


# 球体の中心位置リストを作成する

centers = []

for i in range(5):

    z = -30 + i*15

    centers.append(Vector((0, 0, z)))


# 目標位置を指定する

target_location = Vector((-30, 0, 0))


# フレーム数を指定する

last_frame = 600


# 移動する距離を指定する

distance_per_frame = 0.1


# スフィアの作成

for center in centers:

    bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, location=center)

    sphere_obj = bpy.context.active_object

    sphere_obj.name = "Sphere Z軸" + str(centers.index(center))


# アニメーションの作成

for frame in range(last_frame+1):

    for obj in bpy.data.objects:

        if obj.name.startswith("Sphere"):

            distance = (target_location - obj.location).length

            if distance > 0.01:

                direction = (target_location - obj.location).normalized()

                obj.location += direction * min(distance_per_frame, distance)

                obj.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

# メイン関数
def main():
    # フレームレンジを設定する
    set_frame_range(1, 640)

# スクリプトを実行する
if __name__ == "__main__":
    main()



改良中 y=-30 中心 円周への球体36個

できた y= -30 中心で z=0平面移動  import bpy import math zion_collection_name = "線路レール 観察者" # コレクションを作成する col = bpy.data.collections.new(zio...