Animation State Interpolation and Physics Simulations

Dev Blog #2 by George Baron

06 October 2019

This Week

This week was slower going than last week due to feeling a little burnt out. Not to say progress hasn’t been made though. At the start of the week I made a quick walking animation and worked on skeletal animation state interpolation. In lay-man’s terms, this just means when I want to swap between different character animation states (say from an idle animation state to a walking animation state) I can insert a few extra, generated poses to smoothly transition from one animation to another. If I don’t do this, there is a super noticeable jump when I suddenly change the playing animation!

Additionally this week I started on a rather big part of the engine I’ve been sliiiightly putting off. At the minute there is no collision or any notion of physics. I’m just sliding about a character by updating its position and rotation. This is obviously no good and I need some actual physics happening so I can at least bump into objects. Unfortunately this is quite a big thing to suddenly insert into an engine and it needs a lot of careful planning. More on that below!

I also took some time this weekend to improve the website somewhat. I’ll slowly be improving this over time to include various missing features.

Animation State Interpolation

This section is specifically to do with skeletal animation. If you’re not sure what that is, then this wikipedia article does a fairly decent job of explaining it. Initially I was just fixing a bug where I couldn’t actually play any other animation besides whatever I loaded last, since I had only tested the system with one animation at a time like an idiot. Once I could actually play more than one animation (the future is now!) I noticed it was horribly jarring when the animation states changed. So to fix this, I decided to implement a system that could linearly interpolate between two different animation states. Funnily enough, this is actually pretty damn easy to do! Skeletal animations themselves are already just a bunch of poses that you interpolate between, so most of the logic is already there! All I had to do when an animation was called to play was store the current pose, set the next animation playing and slowly transition from the stored pose into the playing animation.

Explaining like this is a bit rubbish though, so below is a comparison.

Left: no interpolation. Right: interpolation. The difference is very noticeable!

Physics

The other main thing I did this week was start implementing a real-time physics engine. I made the decision to not write it myself to save time - admittedly, writing a whole game engine isn’t exactly “saving time” but I know how to pick and choose my battles. I have confidence that I probably could write one myself and hell, maybe in the future I will re-implement it myself, but for now I decided to use someone else’s physics engine. In the past I have played with the Bullet real-time physics engine, but recently it seems to have shifted its efforts over to being Python focused. Even their domain has changed to “pyBullet”! If it hadn’t shifted its focus like that, it was still a C++ library primarily. Since I am using C# for my engine, I checked out some of the C# binding libraries but it all just seemed like a faff in the end.

Instead I opted to find a C# physics engine; hopefully with a Nuget package so it’s nice and easy to just drop into my project and have a running start. It didn’t take too much looking until I found something absolutely perfect!

BEPU Physics

First things first, BEPU Physics is absolutely brilliant. It’s free, open source, written in pure C# and was designed against .NET Standard 2.0. This means it will also work cross-platform in .NET Core applications! And if that wasn’t enough, they also provide plenty of demos to get your teeth into in their Github repository. This made the whole learning process so much easier and has helped immensely with integrating it into my game engine. I’m not finished with the integration at all so I have nothing to show yet, but hopefully by the end of next week I will have something. I am pretty damn excited to have it working though!

Seriously though. This thing is awesome. They are awesome. I am very glad this thing exists to make my life easier.

Website Development

The final thing I did this week was not game related. I have made a couple of improvements to the website! Most noticeably, I now have Twitter previews working (which should hopefully also work with other applications like Discord), I have a page that lists all of my blog posts, and blog posts show their posting date now. Website development is likely to be a continuously on-going thing since my main commitment is still, you know, making a game. But it is nice to have a decent looking and functioning home to come back to every Sunday.