Script for constraints/adding objects?

Hello all,

I’m hoping to get an object to pick up another object(food) which will make it longer (have another object adding onto it) kind of like that retro game with a snake! Can anyone be so kind to point me in the right direction?

I’m scripting this.
I’d also just like to say blender is AMAZING! I haven’t had a chance to tell anyone that, and I’m super excited to use it!

If I need to add anything to make my question more attractive, I’ll be happy to do so.

bump?

anyone? :slight_smile:

Can you specify if you’re trying to do this as an animation or is this game engine?

To add a constraint with python, imagine a scene with a cube called ‘Cube’ and another object call ‘Parent’. Let’s say I want to add a child_of constraint to the cube targeting the parent. I would write a script like this:


import bpy

scene = bpy.context.scene

cube = scene.objects['Cube']
parent = scene.objects['Parent']

constraint = cube.constraints.new('CHILD_OF')
constraint.target = parent

However, this will not get you the snake game. That’s going to take more coding and creativity.

Thank you for replying! This is for a simulation.

Would it be worth adding a path/curve to the object I want objects to track to? So then, maybe they could pile on like a string of beads behind the parent once they are called to constraints? Especially if they have collision properties?

Or maybe it is worth adding sensors! I’m sure that sensor properties can be called in script.

Also, thank you for the script! This is exactly what I was looking for :slight_smile: