Attaching Items to Camera using CoBlocks

How do you code an item to attach as a child to the camera? Eg, I have a student that wants to ‘hold’ a key so that when they bump into the door it will open.

Hi @iaincb,

The easiest way to do that is to use the add and detach blocks in CoBlocks. They’re located in the Items category. Below is an example space. You can press the remix button to copy this space and take a look inside the code :slight_smile:. The second scene also demonstrates how to achieve this behavior in script.

1 Like

Hi Stefan,

Thanks for your answer! I found a second way that works more how the student wanted it to. In your demo the key is directly and immediately in front of the camera.

What I did was to create an invisible cuboid and make that a child of the camera. The key then attaches to the cuboid rather than the camera itself. This lets the creator place the cuboid so it looks to be in a more natural holding position.


Hi @iaincb,

That’s a really clever idea to ensure the correct holding position! Looking forward to the projects that will be done with it :slight_smile:

We’ve gone one better. Now we have a hand model from Google Poly (this is a great addition BTW!), so that the key can be ‘held’

We thought it would be great if there was a CoSpaces animated hand that would have open and closed animations…

This makes it feel much more natural when using.


Hi @iaincb,
Can you share the Google Poly hand space as remix?
Thanks in advance!

Hi there :smile:

Sure can! Here is the link to the space.
It is also now in the gallery.


1 Like

Hello, can you briefly explain, show me how you placed the hand so that it would not collide with the floor?
thx Gerrit

because it is forced

(It says move so is forced to move, it will also phase through stuff because it directly changes its position (X, Y, and Z))

@Stefan Is there a way to do the code above in Python?