Yesterday I implemented a small feature in my prototype where my little dog can dig up a bone:
The dig interaction is available if the dog is in a dig trigger area and the user holds down the down arrow key. After 4 seconds of digging, a bone appears that can be consumed by running through it, which triggers a flying stars effect.
Here is the implementation of this feature in Unreal. You can click on the images to make them bigger & more readable.
1. Input settings. This sets the down arrow key as the user input for triggering the Dig interaction.
2. Dig Area. This is an empty actor with a collision sphere attached. Its blueprint triggers an event when the dog enters the sphere:
Settings for the trigger collision sphere:
Trigger Area blueprint:
3. Character blueprint. This contains the logic for determining whether the dog can enter the digging interaction and spawning the bone. Right now it doesn't destroy the trigger area or spawn a dirt mound model to mark the dug up area, this will be added in a later version.
4. Animation setup: Animation has a IsDigging variable that corresponds to the one in the character blueprint. It is set in the Event graph of the Animation blueprint. Note that you have to cast the Pawn Owner to the Pet Character to get access to the Character BP IsDigging variable.
The dig animation has a start, a digging loop, and a stop animation. These are set up in a pretty standard way in the animation statemachine:
Transition logic between the states:
5. Finally, the Bone blueprint. This is attached to the bone mesh (which has a collision box) and contains the logic for destroying the bone and playing the stars effect when the dog runs through it.