I’m wondering what would be the best way to design some reusable code for AI-controlled NPCs with animations. Like how should I design the GameObject hierarchies and what to put into the scripts to make a reusable architecture that can be specialized for different types of NPCs. As it stands, I got all this stuff to work in a single NPC GameObject, even implemented realistic IK foot placement, but it’s so messy and specific it’s not portable at all … only the IK foot placement is reusable.
How should I go about setting the value range in my animation blend trees, and what script should be setting them each frame? Where should I extract that “speed” value from to determine what value to set? The way I did it so far is by taking the navmeshagent velocity, converting to magnitude and determining what % of its max speed it’s traveling to set a blending value between 0 and 1 (0 is idle, 0.10 begins walking and 1.0 is full sprint). But I’d like to have some kind of portable “Character” class that’s going to figure out how fast a character is moving through the world (regardless of what’s moving it – whether it’s the navmeshagent or some custom logic or even the editor move tool) and automatically make the animations match the movement speeds and directions. Basically, I want his feet to be doing the right thing to match how he’s moving at all times. And of course I can interrupt that for things like making him stumble from being hit or something.