Results 1 to 2 of 2
  1. #1

    How to smoothly rotate an object

    Hi, I am trying to rotate an object from one direction to other direction. How can we make it smooth rotation? Right now it is making a jumpy rotation with the following code. Thanks in advance

    import bpy
    import mathutils 
    context = bpy.context
    scene = context.scene
    obA = scene.objects.get("Cone")
    obA["speed"] = 0.1
    def setloc(scene):
        a =["Scene"].frame_current
        if a < 60:
            loc = mathutils.Vector((8.0, -0.05, 0.0))
            dv = loc - obA.location
            loc = mathutils.Vector((-10.0, 14.05, 7.0))   
            dv = loc - obA.location
        rot_quat = dv.to_track_quat('Z', 'Y')
        obA.rotation_euler = rot_quat.to_euler()
        speed = obA["speed"]
        if speed > 0.000001 and dv.length > 0.000001:
            obA.location += speed * dv.normalized()

  2. #2
    Join Date
    Jul 2012
    You're currently using an if-else statement to do the rotations hence why it is jumpy.

    If you want the rotations to be smooth then you will have to change your code so that it uses spherical interpolation between the two rotation states over a small range of frames.

    For example, if you want the object to rotate smoothly around frame 60 then you'll have to interpolate the rotation from, say frame 55, to, say frame 65 depending on how fast you want the rotation to be.
    Modeling Practice - [HERE]
    Refraction Based SSS Shader + An All Purpose Shader (Experimental) - [HERE] (Download Unified Shader - All is within)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts