Here is a step-by-step instruction on how to create a pick-up object, set it up in your scene, and create a pick-up mechanic for it.
Upon the completion of the steps below, you will have a coin that disappears when a character picks it up in the game.
Create a Pick-Up Object
In this sample, we created a coin as a pick-up object. We selected a cylinder object from the Library of primitives. Move the cylinder in front of the main character.
Could not load image
To make a cylinder look like a coin, we rotated it to 90 degrees by X-axis, flattened its size by Y-axis to “0.1” value, and changed the base color to Yellow.
Create a Pick-Up Group
To keep your game project organized, we recommend creating a group for your new pick-up object first. To create a group, select a cylinder object from the scene tree, click RMB => Group. Then, rename this group to "Pick-Up".
Create a Pick-Up Collider
A Collider forms a trigger zone for the object which is a key element in creating further pick-up animations. To create a collider, select a cylinder object inside your pick-up group. Then, go to the Physics tab, toggle YES for Physical and select Ghost type of Rigidbody. The latter will have the Cylinder collider appear around the coin. We recommend adjusting the scale of the collider so that it appears slightly smaller than the size of the pick-up object (cylinder). In our example, the radius is at 0.4, and the height is at 0.1 for directional Y-Axis.
Animate the Coin Pick-Up Mechanic
This section describes two main steps completed in the Animation mode to make a coin disappear when it gets picked up by the main character. The first step describes how to create a keyframe in the animation timeline to enable the pick-up object. The second one demonstrates how to apply the trigger for the main character to launch this animation.
Create a Keyframe to Enable the Pick-Up Animation
1. Create a new animation in the Animation Mode and rename it to "Pick-up Mechanic" using the RMB. Make sure that this animation is inside the Pick-Up group.
2. Add a cylinder object from your pick-up group into the animation timeline to create an animation track for the object.
3. Let’s disable the cylinder object in the timeline tab by adding an animation track of the object's parameter. To do that, hover your mouse cursor over the cylinder and click on the (+) button. Then, select the <Enabled> option from the drop-down menu. Use RMB to click on the 1.0 point in the keyframe and uncheck Enabled to "NO".
Set Up a Trigger For the Main Character
To apply the above keyframe settings for your coin pick-up mechanic, you need to set up a trigger for the main character. To do that, go to the Triggers tab, click on the Add New Trigger button and select Collision Started from the drop-down menu.
In the trigger, click on Any Object, and select MainCharacter > MainCharacter Body.
Then, click on No Object, and select Pick-Up > Cylinder.
If you run your game in the Game Mode, you will see that the coin disappears when the main character picks it up. This event occurs because the Main Character’s collider meets the coin’s collider that, in turn, triggers the pick-up animation.