Creating Animation Without Keyframes or Drivers in Blender

Creating Animation Without Keyframes or Drivers in Blender
Photo by Feelfarbig Magazine / Unsplash

Today, I've been learning how to create an animation without using keyframes or drivers. Instead, I used a handler to update the positions of an object for each frame change.

The initial idea was to create a 70s-style Ping Pong video game animation, but I was only able to make the ball move. The paddles, which were separate objects, didn’t move at all.

The basic idea is to create an object, set variables for its positions, and write a callback function to update those positions within the handler. This is necessary because Blender doesn't support statements like 'if,' so the calculations had to be moved to the callback function.

Here’s what the callback and handler look like:

# Movement variables
pos_x = 0.0
pos_y = 0.0
speed_x = 0.04
speed_y = 0.025 

# Callback function to update the ball's positions
def update_object_positions(scene):

    # Add as global variables
    global pos_x, pos_y, speed_x, speed_y

    # Update the ball's position ('ball' references the 'Ball' object)
    ball_object = ball.object
    pos_x += speed_x
    pos_y += speed_y

    # Check for boundaries and switch speed
    if pos_x > 1.8  :
        speed_x = -speed_x
    if pos_x < -1.8:
        speed_x = -speed_x
    if pos_y > 1.8:
        speed_y = -speed_y
    if pos_y < -1.8:
        speed_y = -speed_y
    
    ball_object.location = (pos_x, pos_y, 0)

# Register the handler to update positions on every frame change
bpy.app.handlers.frame_change_pre.append(update_object_positions) 

Here's what it looks like: