import bpy
#Prepare the object you want to move
bpy.ops.mesh.primitive_uv_sphere_add()
#Variable preparation
x = 0
y = 0
z = 0
x_speed = 5
ob = bpy.data.objects["Sphere"]
frame_num = 0
for i in range(0,100):
bpy.context.scene.frame_set(frame_num)
#If the x coordinate of the object is greater than 100
if (x > 100):
#Return to the starting point
x = 0
#The x coordinate of the object is x_Shift only speed
x += x_speed
ob.location = (x,y,z)
ob.keyframe_insert(data_path = "location",index = -1)
frame_num += 1
import bpy
bpy.ops.mesh.primitive_uv_sphere_add()
x = 0
y = 0
z = 0
x_speed = 5
ob = bpy.data.objects["Sphere"]
frame_num = 0
for i in range(0,100):
bpy.context.scene.frame_set(frame_num)
#The x coordinate of the object is greater than 100 or-If less than 100
if (x > 100 or x < -100):
#Invert
x_speed *= -1
x += x_speed
ob.location = (x,y,z)
ob.keyframe_insert(data_path = "location",index = -1)
frame_num += 1
import bpy
bpy.ops.mesh.primitive_uv_sphere_add()
x = 0
y = 0
z = 0
x_size = 10
y_size = 10
z_size = 10
x_speed = 2
s = 3
ob = bpy.data.objects["Sphere"]
frame_num = 0
for i in range(0,120):
bpy.context.scene.frame_set(frame_num)
If the x coordinate of the object is less than 30
if(x < 30):
s = 3
If the x coordinate of the object is less than 60
elif(x < 60):
s = 6
If the x coordinate of the object is less than 90
elif(x < 90):
s = 9
If the x coordinate of the object is greater than 120
elif(x > 120) :
x = 0
x += x_speed
ob.location = (x,y,z)
#Change the size according to s
ob.scale = (x_size * s,y_size * s,z_size * s)
ob.keyframe_insert(data_path = "location",index = -1)
ob.keyframe_insert(data_path = "scale",index = -1)
frame_num += 1
import bpy
bpy.ops.mesh.primitive_uv_sphere_add()
#r =Radius of circle
r = 10
#Range to move around
x_domain = 50
y_domain = 50
z_domain = 50
x = 0
y = 0
z = 0
x_speed = 7
y_speed = 3
z_speed = 5
ob = bpy.data.objects["Sphere"]
frame_num = 0
for i in range(0,100):
bpy.context.scene.frame_set(frame_num)
#Invert the direction of the ball when each threshold is reached
if (x > x_domain-r or x < -x_domain+r):
x_speed*= -1
if (y > y_domain-r or y < -y_domain+r):
y_speed*= -1
if (z > z_domain-r or z < -z_domain+r):
z_speed*= -1
x += x_speed
y += y_speed
z += z_speed
ob.location = (x,y,z)
ob.keyframe_insert(data_path = "location",index = -1)
frame_num += 1
Recommended Posts