-
-
Save DarthMoulByte/e24814db0210f5351888fe1634228880 to your computer and use it in GitHub Desktop.
This file contains hidden or 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