Attaching Items to Camera using CoBlocks


#1

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.


#2

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.


#3

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.


#4

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:


#5

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.


#7

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


#8

Hi there :smile:

Sure can! Here is the link to the space. https://cospac.es/iWX9
It is also now in the gallery.

regards,
Iain