Make path move like snake in snake game In my game I have a Nurbs curve in the XY plane. I have a rigged car, that has a follow path constraint, so that it follows this curve.

I would like to make the Nurbs curve behave like a snake in the snake game. The snake should move by extending its head and cutting off its tail. When the player presses the 'up' arrow, the head should extend forward and the tail should be cut off. When the player presses the 'right' arrow, than the head should make a turn to the right, and idem for the 'left' arrow.

Is it possible to do that? In the pictures, the dots are the vertices of the Nurbs curve. I can give more details if necessary. Thanks :)

Examples of the curve turning to the left, the right, and moving straight:
The following code moves each point in the curve ahead one spot.
So the second point moves to where the first point is, the third to the second, and so on.

All you need to do is decide where the first point needs to be moved next.

import bpy

# Assumes your curve is the only one in the scene.
curve = bpy.data.curves[0]

items = curve.splines[0].points.items()
point_count = len(items)

for index in range(point_count - 1, 0, -1):
    current = items[index][1].co
    previous = items[index - 1][1].co
    current.x = previous.x
    current.y = previous.y
    current.z = previous.z

first = items[0][1].co
first.x -= 1


The final part moves the first point to the new position.
So you could do first.x -= 1 for left, first.x += 1 for right, and first.y -= 1 for forward.
This is making assumptions about the orientation of the scene, so you should adjust x, y, and z to suit your scene.

This code is very simple, but hopefully it is enough to get started.