✊Pick Up - Drop
✔
Last updated
✔
Last updated
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.
It requires any type of collider set as Trigger.
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.
All the Objects that can be picked required to have the Pickable component on them. Learn more about it on its section.
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.
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.
Reference to the Collider used as the Interaction Trigger
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.
When an object is picked, it will parented to this transform. Until is dropped
It adds some offset to the picked object relative to the Holder position and rotation.
Current Picked item. Set this reference on the editor to start the game holding an object.
This parameter will show the current focused item that is inside the Interaction Trigger.
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.
Is invoked when an item is picked. Uses as parameter the Pickable gameobject
Is invoked when an item is focused. Uses as parameter the Pickable gameobject
Is invoked when the item is picked. Uses as parameter the Pickable ID
Is invoked when the item is dropped. Uses as parameter the Pickable ID
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.