jpw1991 / chebs-mercenaries

Cheb's Mercenaries adds mercenaries to Valheim that you can purchase with gold and upgrade with materials to fight (warriors, archers) or perform work (lumberjacks, miners).
The Unlicense
3 stars 3 forks source link

Idle Activities for Mercenaries (eg. sitting in chairs) #48

Open jpw1991 opened 7 months ago

jpw1991 commented 7 months ago

Multiple people have reached out to me in various forms about creating more lively mercenaries. For example, mercenaries that will sit in chairs or do emotes, talk to each other, etc.

This is 100% doable. I'm outlining the process by which this would/could be achieved so that others might have a go at it. It'd be great if someone else did it because I want to focus on other things first.

Approach: Find and Sit in a Chair

For simplicity, let's focus on just one behaviour now: Making an NPC approach and sit in a chair.

I think that creating and using a new script called something like MercenaryIdleBehaviours.cs or similar would be the go. This script would utilize the existing MonsterAI in Valheim for the purposes of approaching objects and interacting with them. For a great example of a minion that approaches things and interacts with them, I recommend looking at the Neckro Gatherer from Cheb's Necromancy because it has the most interactions with the outside world of any of my creations.

The Cycle

SitInChair

Whenever a minion is following something, this refers to MonsterAI.FollowTarget which is typically the Player (following), a Wait Object (waiting), or null (roaming). It can be used to tell the AI to move toward something too - like a chair. This will use the game's underlying pathfinding etc. to make the minion move to the chair. Enemies nearby is a different interaction and takes precedence over whatever is being followed. For example, if the minion is following the player and an enemy approaches, it will chase that enemy before returning to the player.

Finding Nearby Furniture

Sitting on the Furniture

The sitting animation is currently absent from the mercenaries because their animation tree is based off the far simpler skeleton one. We'd need to change it to be the player animator (probably best) or at least add these triggers and animations to the existing animator:

image

The player animator is gigantic and insane and parts of it may be inappropriate for minions (eg. animations having triggers that only players should have). So it might be best to just copy the chair stuff out of it and add it to the far smaller and far more managable existing animator. Here's the player animator for reference:

image