2
$\begingroup$

I am trying to move an object in 3d environment using blender python script similar to this https://www.youtube.com/watch?v=bEo8YRHysp8. I tried with the following code but ended up in jerks in movement and also the movement was not clear. Please help me thanks in advance.

import bpy
import math
import mathutils
import random

bpy.app.handlers.frame_change_pre.clear()
ob = bpy.data.objects.get("Cube")
ob.location = mathutils.Vector((0.0, 0.0, 0.0))

# every frame change, this function is called.
def my_handler(scene):
if random.randint(1, 10) > 9:
    x = random.uniform(-0.7, 0.7)
    #print (x)
    vec = mathutils.Vector((0.0, x, 0.0))
    ob.location = ob.location + vec
else:
    vec = mathutils.Vector((0.0, 0.0, 0.0))
    ob.location = ob.location + vec


bpy.app.handlers.frame_change_pre.append(my_handler)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.