Links

Pick Up - Drop

✔

Overview

This component allows the animal to carry single objects, carry and drop them. At the moment only can carry one object.
All the Objects that can be picked required to have the Pickable component on them.

Requirements

Collider

It requires any type of collider set as Trigger.

Trigger Proxy

It needs the Trigger proxy component, which uses the OnTrigger Enter OnTrigger Exit callbacks to know which objects enter the Trigger. If this component is not added in the Editor. it will be added at runtime.
It is recommended to add it on the Editor so you can set the Layers to interact with the Pick Up Component.
Layer set as Items to only recognize gameobjects set with the Layer Item.

Pickable

All the Objects that can be picked required to have the Pickable component on them. Learn more about it on its section.

How it works

The animal will use the Trigger Area assigned to find pickable objects. If any of this objects enters the Trigger area the Pick component will focus on the object.
To continue the Pick logic, you can assign an Input to execute the TryPickDrop method.
This will execute the Pick Logic when there's an item focused and it will execute the drop logic when the animal has an item picked.
Some of the properties are handled by the Pickable component on the item.

How to set it up

You can create an internal Gameobject inside the character hierarchy to have a cleaner and organized components just for the Interactions components.
1.- Add the Pick Drop component.
2.- Add the collider and set it as trigger and fill the reference to <Pick Up Area>
3.- Set the GameObject used for the Pick Drop as Ignore raycast. That way the collider will not be recognized as part of the animal.
4.- Add the Trigger proxy component and set the Trigger proxy Layers and Trigger interactions to your needs.
5.- Add a new Input to your character and set the MPickUp.TryPickUpDrop() method to the Input.
6.- Use the Events of the Pick - Drop component to Enable and Disable features on the animal. E.g. When the animal has an object picked, Its necessary to disable the Attack and the Actions Modes, so the animal wont be able to attack, eat, drink or sleep while is holding an object.
7.- Check on the side of the Pickable component what its needed to make the Pick component to work properly.

Parameters

​

Pick Up Area

Reference to the Collider used as the Interaction Trigger

Hide Pick Area

When this is set to true the Pick Area will be disabled when the animal picks an object. Limiting the animal to pick any other object until it drops the one it has.

Holder

When an object is picked, it will parented to this transform. Until is dropped

Offsets

It adds some offset to the picked object relative to the Holder position and rotation.

Item

Current Picked item. Set this reference on the editor to start the game holding an object.

Focused Item

This parameter will show the current focused item that is inside the Interaction Trigger.

Events

​

On Can Pick Item (Boolean)

Is invoked when there's an pickable object inside the interaction area. True when there's an object, false when the object exit the area.

On Item Picked (GameObject)

Is invoked when an item is picked. Uses as parameter the Pickable gameobject

On Item Focused (GameObject)

Is invoked when an item is focused. Uses as parameter the Pickable gameobject

On Picking (int)

Is invoked when the item is picked. Uses as parameter the Pickable ID

On Dropping (int)

Is invoked when the item is dropped. Uses as parameter the Pickable ID

Methods and Properties

Pickable FocusedItem {get;}

Returns the current focused item inside the Trigger
​

bool Has_Item {get;}

Returns whether the character has an item or not

public Pickable Item {get; set;}

Returns the current hold Item

void TryPickUp()

Tries the pickup logic checking all the correct conditions if the character does not have an pickable.

void TryPickUpDrop()

Tries the pickup logic checking all the correct conditions if the character does not have an pickable, or the Drop item logic when the character is carrying a pickable.

void TryDrop()

Tries the Drop logic when the character is carrying a pickable.