Adding some realism to player movement

We’ve been quite happy with the handling of the helicopter you control for quite a while now, but it’s spent most of the time just gliding through the air without any real animation. I had a go at fixing this a while ago using two different methods: One of these methods failed spectacularly, the other in the most mundane way possible.

Take one

The original method was to rotate the the chopper along one of its axes based on the direction it was headed in and it seemed to make perfect sense before I tried it. Thankfully the reason it failed made itself apparent really quickly:

The player is moved using Unity’s physics system. Obviously we haven’t tried to simulate the physics of a real chopper, but pushing the player with forces meant we could capture some of the characteristics of a chopper and get better reactions on collisions. The input system basically shoves the player forward while they’re pressing forward, sideways when they press sideways, etc, while momentum handles some of the expected handling characteristics. The problem with rotating the player was that when we pitched the chopper forwards, the forwards direction of the force was also adjusted, making the player perform a rather dramatic nosedive whenever they moved forwards. It looked amazing and I definitely had a good laugh for the 2 minutes it was in place, but that really wasn’t going to work.

Take two

The other method was a bit hopeful, really: I’d used Mecanim (Unity’s animation system) for the Stealth tutorial that Unity provides, but I wasn’t really all that sure of how to use it effectively. It also meant that I had to create a few different animation states for the player using Blender (the 3D modelling tool we use for the game’s assets) which I wasn’t all that comfortable doing. This combination of uncertain and uncomfortable meant that the end result was about  two hours of setup work and a chopper that did…well, nothing. Worse than nothing, really – it broke the rotor animations that were working fine before. Oops. I’ll come back to this later then…

Some time later…

Fast forward a couple of months and I knew that a reworking of the first method was the only real way that this was going to work. Thankfully, working on other parts of the game had made me realise that there was a really simple solution to get it working without meeting a violent end as soon as you moved forward – a container object.

I won’t go into detail about why that particular solution works, but it essentially means that the player gets pushed forward in the same direction, while a separate object rotates the physical representation of the player, making it look like a chopper should without actually simulating all the complicated forces and effects on a chopper in flight.

Amazingly, I got it working without any major issues within an hour and Miles and Dan gave their approval. A brief testing session later, Miles rather sensibly pointed out that the animation should be based on player input, not their current velocity, and after some quick changes we were left with the following:

Obviously everything is still being worked on. The animations have prompted a few conversions about the player speed and various other things that we still need to tweak and decide on, but after spending months looking at a chopper gliding through the air during testing, we’re all rather pleased with it!

Other updates

We had a really productive meeting last week going through Miles’ reworking of some old code and Dan’s first sketch of the level layout and his plans for adding more detail.

Since then, Miles has reworked more of the code with a view to us finishing the job the next time we meet up, Dan has been adding more details to the level and tweaked some of the existing models, and I’ve added some code so we can change some of the environmental effects when in certain areas of the map.

Up next: reworking the badly (oh so badly) broken aiming system, adding in another weapon for the player (hopefully), and more level design work.

We’ve also set up a page for mailing list sign-ups here. We’ll obviously not use your email address for anything else and emails will likely be (very) rare, so you’ll not get spammed. We’ll almost certainly be asking for testers via this list, so you know what to do if you’re interested!

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.