Hi anyone! One of the things I like about game development is that there are many ways to solve every problem. The challenge is that the only way to know what solution works is to implement it and see.
Stay with me, I’ll try to explain. We are working on a new character controller for our goblins. One of the most basic problems to solve is how we translate player input (e.g. a push forward on the joystick) into movement in the game. There are a ton of ways to do this. To name a few:
- Be Direct – Get a vector directly from the input each frame, translate it into world-space, and use it to move the Goblin. This is the most responsive- but that might not always be what you want.
- Use an Intermediary – As above, get a vector from the input each frame but use it to modify a “movement” vector. This could help smooth out acceleration/deceleration- but could also lead to controls that feel sticky or unresponsive.*
- Use The Animation – Take the input and use it to make animator parameters. Then, each frame, get the animation’s movement from the animator (Unity calls this ‘rootmotion’- maybe other engines do too.) Then use the vector given by the animation to move the gob.
- All of the Above – Use an intermediary to derive the animation parameters, and combine the direct input vector with the root motion vector to get movement. Is this convoluted as heck? Yes. Did we try it anyway? You bet.
Where you get your motion vector is only half the story. We also have to decide how to apply the motion to the Goblin. Luckily, I only know of two ways to do this:
- By Directly Setting the Velocity of the Character Controller** – Each frame, you calculate what the velocity of the character controller should be based on the movement vector and set it directly. This gives very precise control over the movement each frame- but comes at the cost of interaction with the built-in physics engine- meaning you’ve got to handle a lot of things, like gravity, yourself.
- By Applying Force to The Character Controller along the Movement Vector – This plays nice with the built in physics engine- which allows for more interaction with the tools Unity already give us. The downside is it plays nice with the built in physics engine- which means we have to account for the unintended consequences of the tools Untiy gives us.
In WOFG! The Demo! we are currently using rootmotion from the animation and setting the velocity of the character controller directly (plus some convoluted nonsense to manage slopes). We’ve tried a lot of movement options/experiments for the the new goblin but we think we’ve settled on using an intermediary movement vector to smooth acceleration and applying the force using AddForce().
The upside is we don’t have to worry about accounting for slopes, moving platforms, etc. in our calculations. We get that stuff from the physics engine. The downside is that the movement feels “slippery” like we’ve got permanent ice physics. The breakthrough over the last few weeks was to boost the intermediary vector when the goblin’s velocity is low- i.e. when they are just starting or stopping movement. We think this gives us the best of both worlds- we have enough settings to tweak to get the behavior we want, but we also get the benefits of using Unity’s built-in tools as much as possible.
It’s feeling good to run around with our new Goblin- but it is taking longer than either of us expected (we probably should have expected- but that’s a story for another day). I’m optimistic we are on the right track now and should have more news to share soon. At the end of the day, it’s going to take the time it takes. It will be worth it to get this right.
As always, thanks for reading. I’ll be back next week to blog about something. Cheers.
* There are a bunch of sub-decisions to make within this decision (all decisions really). Like how do you modify the intermediary Vector. Do you just add the input to the last move vector? Do you lerp between them? Do you do an esoteric bullshit calculation that tries to factor in slope and obfuscates what you are actually trying to accomplish- Make movement feel heavy without feeling unresponsive? That last one is personal- its the movement we’ve got in WOFG! The Demo! right now. I’ll never show it to anyone out of shame. It’s a mess folks.
** To avoid confusion. When I say “Character Controller” in the context of the goblin I mean “Rigidbody attached to the GoblinActor component” not to be confused with Unity’s built in CharacterController component. Which we don’t use. We probably could use it- but there’s another solution to test out and there’s only so much time in a life and you get the idea.

Leave a comment