Attach to Body Part
-
Introduction
Suppose we have an avatar with a dancing animation, and we want to place a hat on the avatar’s head. If we set the avatar to be the parent object of the hat object, the hat will not move with the head. This is because the avatar’s position is not changing when we play an animation.
To make it look like the avatar is actually wearing the hat, we need to attach the hat to the head of the avatar.
The “Attach to Body Part” Block
To use this block, you need to follow these 3 steps:
- Create a “host object”: this object needs to support animations, so it can be an avatar or a “character” model (like an elephant). You must give this object a name when you create it.
- Create the object that will be used as the attachment, such as a hat.
- Run the “attach to body part” block
Body Part Name
You can attach the object to different parts of the host object. This dropdown allows you to specify which part to use. For example, if you select “Head”, then the object will be attached to the “Head” part of the host object. Note that not all parts are supported by all types of host objects. You can either try it out, or look up the host object’s type in the “Reference - Body Parts for Different Models” section below.
Host Object Name
This is the name of the object (the avatar or character model) that you will use as the host. Note that if you leave this empty then this block will not do anything.
Sprite for Host
You need to select the name of the sprite that creates the host object, which can be different from the sprite that creates the object to be attached.
Height of Object After Attaching
You can specify how tall you want the object to be after it has been attached to the host object.
Demo
In this program, we will attach a blue hat to the head of an avatar:
Note that the avatar is named “p” so it can be referred to in the “attach to body part” block. Also, we have to rotate and move the hat for it to fit with the head. It will take some trial and error to find out exactly how much to turn or move the hat object.
Here is what you get:
You can try this demo project yourself here:https://play.creaticode.com/projects/d80c9dab952dba48dc1a78ec
Note that the hat will be moving for 2 reasons: either the head is moving due to some animation of the avatar, or the avatar itself is moving or turning. So long as the head is changing its position or direction in the world, the hat will do the same.
Reference - Body Parts for Different Models
As stated earlier, different models have different body parts. So if you want to attach an object to a host object, please look up the model for that host object below to find out which body parts are supported. For example, many animal characters do not have a “Chin” part, so we can’t really attach any object to those animals’ chin.
- Default for All Avatars from ReadyPlayerMe: Head, Spine, Left Shoulder, Right Shoulder, Left Hand, Right Hand, Left Leg, Right Leg, Left Up Leg, Right Up Leg, Left Foot, Right Foot
- Default for All Animal Characters: Head, Spine, Left Hand, Right Hand, Left Foot, Right Foot
- Elephant 3: Head, Spine, Left Hand, Right Hand, Left Foot, Right Foot, Left Shoulder, Right Shoulder, Chin, Left Ear, Right Ear, Nose Bridge
- Giraffe: Head, Spine, Left Hand, Right Hand, Left Foot, Right Foot, Left Shoulder, Right Shoulder, Chin
-