Last active
May 21, 2023 18:35
-
-
Save p2or/71700962cbcae4fe714e to your computer and use it in GitHub Desktop.
Random XY anim #Blender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import random | |
def random_floats(min, max, size): | |
return [random.uniform(min, max) for _ in range(size)] | |
# define a animation length | |
length = 10 | |
# create a list, which contains 10 random x values | |
x_values = (random_floats(0, 4, length)) | |
# create a list, which contains 10 random y values | |
y_values = (random_floats(0, 2, length)) | |
# get selected object | |
obj = bpy.context.active_object | |
# animation start frame | |
start_frame = 1 | |
# frame value | |
frame_number = start_frame | |
# keyframe offset | |
offset = 1 | |
# iterate through length and apply them | |
for i in range(length): | |
# set the frame | |
bpy.context.scene.frame_set(frame_number) | |
# set new location | |
obj.location = (x_values[i],y_values[i],0) | |
# insert keyframe | |
obj.keyframe_insert(data_path="location", index=-1) | |
# add offset value | |
frame_number += offset | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment