Daily Progression — A More Optimized Jump

Today's lecture was about optimizing code and keeping code sections separated into their own individual methods, since we’ve been doing this from the start, I gave myself a pat on the back! :D The next part of the course talked about optimizing the jump and using a return function instead of a ‘permissive’ boolean for a cleaner routine.

First, we reset and refactored our players' code so only the movement remained.

Instead of creating a new jump function, we put in a check for the jump button plus a check to see if IsGrounded, but notice this time around it has a parameter!.

We’re not going to be creating a function, but a boolean!

Since we’re only checking the ground layer with that funky bitshift, we only need to check to see if the collider is hitting anything, if it is, return true, and false if not. Easy Peasy!

And as much as I’m spamming the jump key, there are no double jumps happening and we were able to shrink the code significantly. Awesome!

Here’s the entire Player.cs code currently:

Very nice! Tomorrow we’ll set up a few more animations.

cartoonist, game artist, and wanabe gamedev.