0

I have written up some pieces of code and put them together. I wanted to know where I am going wrong and if there are other ways I can make an object move in a circle (orbit). Here is a piece of code that I attempted to do using key frames.

EARTH = bpy.ops.mesh.primitive_ico_sphere_add(location=(10.0, 0.0, 0.0))
# first and last frame index
nfirst = bpy.context.scene.frame_start
nlast = bpy.context.scene.frame_end


for i in range(nfirst,nlast,10):
    period = (2 * math.pi * math.pow(1.5 * math.pow(10, 11), 3 / 2)) / math.pow(GRAVITATIONAL_CONSTANT * MASS_OF_THE_SUN, 1 / 2)
    total_frames = period * FRAMES_PER_SECOND
    # Multiply by minus one so we orbit counter-clockwise
    radians_per_frame = -1 * (2 * math.pi) / FRAMES_PER_SECOND


    # Set frame like this
    bpy.context.scene.frame_set(i)

    # Set current location like this
    #EARTH.set.location.x = 0
    #EARTH.set.location.y = 0
    #EARTH.set.location.z = 0

    EARTH.keyframe_insert(data_path="location")

Thank you for your help, I hope I was more specific in my question this time!

  • 1
    Related https://blender.stackexchange.com/a/91511/15543 An operator returns a status, eg print(EARTH) above will yield {"FINISHED"} the status set of the operator. Instead after the op use EARTH = context.object. This is how operators work, they set the context. Also using ob.keyframe_insert(datapath, frame=i) removes the need to set the frame on the scene. – batFINGER Dec 11 '19 at 02:53
  • I see that you haven't used key frames. Can you tell me how you made the objects orbit? – LoveNeverland Jan 06 '20 at 11:26
  • 1
    Explained in answer. Uses drivers. Updated code to 2.8x – batFINGER Jan 06 '20 at 11:48
  • I figured it out thank you so much! – LoveNeverland Jan 06 '20 at 11:58

0 Answers0