Categories
Blog Blog Post

Atavism Dev Log 21 – On legs and related movements

Update 21: August 2nd – August 15th

Witty Tagline

On the personal side of things, I’ve gotten back into the swing of work, been living with my roommate from the last two years again, and have had very little time to play video games. I’ve also started running a D&D game for my friends (for real this time) and also finished rereading Dune: Messiah. I think before Children of Dune I’m gonna read Slaughterhouse: Five. Still need to finish The Last Guardian!

On the development side of things, I came, saw, and conquered rewriting the character controller, fiddled with a few odds and ends, and bought an expensive asset that’s actually a great tool.

Onward.

testingGround.PNG
The humble testing ground for player movement.

New Moves

Last week I talked about why I was making a new first person controller – essentially to make it easier to fix and implement some movement features and how I wanted a more physical feeling inspired by the Team Ico games – but I was essentially stumped as to how to go about fixing the simple act of walking over small objects. After that I basically scratched my head for a bit, did some research (with this Jim_West’s post on reddit being the most helpful), and felt it out for myself from there.

To explain the controller from the beginning, it operates every Update to grab user inputs and every FixedUpdate to grab axis movement and calculate everything else. The two main functions for movement are Move() and CheckTerrain().

Move() gets the movement axes inputs and formulates a vector based on the two, gets a modified version of the vector from CheckTerrain() depending on if the player is grounded or not, and uses the current MoveState (walk, run, crouch, etc.) to add force and clamp velocity.

CheckTerrain() is much more complicated (and probably the longest, most complicated function I’ve ever written that isn’t a main for a class). The first thing  it does (as per Jim_West’s reddit post) is raycast from just outside the foot collider’s length away, checking if anything is in front of it, then raycast down twice the Step Height to see if there’s something in the way. If it hits something, it’s either a stair or a slope, so it raycasts from the hitpoint to the bottom of the player capsule to check if anything is in the way.

If it’s going across a slope, I simply project the movement vector across the surface, but stairs will Lerp the player to the desired height (just above a stair going up or to the height of a stair going down). There are a few other bizarre failsafes to keep this working properly, but I figured them out eventually.

After this, luckily enough, implementing jumping, fall damage, and sliding were ridiculously easy with a rigidbody instead of the old PlayerController code. The player can also sprint and walk slowly, so the functionality is almost back to normal (although sliding actually works now, so it’s technically better). To top it all off, writing it all myself was way neater than the code I grafted onto the old controller back when I was new to Unity, which is just 100x easier to deal with.

BirdIK
I ought to finish modelling it’s eye, because right now the oblong shape is kind of sheepish.

Inverse Kinematics

The other big thing I worked on this week was implementing Inverse Kinematics onto the AveApex controller. The price of FinalIK was pretty high ($90, I tried to wait for a sale) but hoo boy. It’s not only feature-packed, but tons of fun to use. With so much mileage to come out of this thing and how fascinating the technology is, I just can’t complain about the price.

For a brief and practical explanation about Inverse Kinematics (IK) in this context, it’s when you target a model’s animations by telling it to be somewhere, overriding or adding to any animations playing underneath. I’ve read up a lot about the structure and math behind integrating it, but decided that refining it to a degree where it would do everything I wanted would be easier purchased than coded; so far, I’ve really appreciated this.

The first thing I did with them was ‘ground’ the bird, which was simply an effort of assigning the bones to a Fully-Body IK controller and attaching a Grounder component with some nifty variables and making sure it only comes on when the bird is in a grounded state. The results can be seen above with the feet. Next I added a LookAt IK script to the Bird’s head, making it crane it’s neck and turn it’s eye to the target when it’s visible. After some light integration and setting up the script, it was already working, and its presence alone really helps to liven the thing up and make it seem more menacing.

One giant problem with the bird’s attack before IK was that it was pretty much useless and tacky unless the bird was facing it’s entire body at the player (within an angle) to begin with, which is what I did. By rigging the head up as a limb, however, I could allow the angle to be much wider and simply play the bite animation with the head targeted towards the bird’s target, resulting in an accurate and natural-looking snip.

BirdCreeping
The more I work on it, the scarier it becomes.

Odds and Ends

Besides the two big things, I got some other stuff done with my time these weeks:

  • Whisked up some PS4 controller support. Turned out to be kind of a pain because some of the thing’s axes were different than what every map I could find on the internet said they would be, so I had to figure them out by myself. Works well though. For now. Hopefully on other computers besides mine, too.
  • Modeled some legs and a torso for the player’s body viewmodel, which I also spontaneously decided I wanted to fully implement. I got to about a walking animation when I decided I’d put it on the backburner though, so don’t go holding your breath for now.
  • Also slapped some IK on those legs. Makes walking over tiny objects even more nice.
  • Made the AveApex more sensibly follow the player when they’re hiding underneath a ledge.
  • Tweaked a bunch of attack ranges and stopping distances for the bird so that it doesn’t just ram into and bite below itself. Feels more natural.
  • Fixed some (but not all) foot sliding for the AveApex.
Leggies
Legs. Kind of at a weird FOV.

Next Update

So following in fashion of previous updates, I said that I’d get A and B done on one aspect of development and be better off for it, but instead I got A done and also C, then planned D shortly afterwards.

I said I’d finish the character controller entirely with climbing and animations, but didn’t do the whole ‘climbing and animations’ thing, instead just plowing right into IK to fix all that’s related issues, which have only caused a chain-reaction racing violently down my backlog, making everything I put off now possible. As a result things could get messy.

Also school starts again next week and I have a really busy semester.

We’ll see how it goes, but I want to get the following done by next update: finish and polish how the bird attacks and defends against the player on the ground, finish the Hanging and Climbing for the player controller. And make the bird take off?

That’s it, there we go. Get that done and I’ll get started on fixing up the bird’s flying problems too. Long-term by a month or two and I want the new player, the polished bird, and a (really) short demo level by September 7th.

Until next time, cheers.

 

By Steven Zwahl

I'm a Computer Science undergrad at Kansas State University.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s