Devlog 1 - Player Movement


This weeks implementation is player movement!

-----------------------------------------------------------------

Goals for player movement: platformer style controls that help traverse a 2D environment including walking/running, jumping, wall jumping when in contact with walls (without being able to infinitely climb them)

What my original goal with the feel of player movement was to make control over the player feel smooth without feeling super floaty. I decided to use Unity's physics system as a base for my own project over making aspects of it myself as it would be 1. easy to get started with (a lot less ground work before getting basic movement working) 2. I'm bad at basic physics/collision (I've done it before but it gets very messy) and 3. it would be a lot less time as this project has a limited timeframe and I can't spend forever on it. Although I like to have as much control over my project as I can, this is definitely the call.

I made simple movement that increases the velocity of the player in the direction pressed to a certain maximum (which only applies to being on the ground) and jumping mechanics by using Unity's boxCast to check if the player was grounded (invisible box like a raycast to check anything under the player) then launches the player with a strong upwards force and gravity is handled. This was ok for a start but changing directions definitely took way too long so I made increased acceleration for swapping directions when on the ground (as air control should be slightly lower IMO). Friction applied to the walls created wall sliding which would be amazing for wall jumping when I got to it and solved the problem of the player sliding crazy distances before stopping.

Once that was out of the way, I took some time creating animations for standing still and running which I'll implement later with a wall slide, jumping and falling state as well. Currently the only one actually in the game is the idle animation but that will change a bit later on.


^^^ Very low quality and terribly looped gif of WIP run animation

Then it was time to upload it to Itch and.... it broke. As all the feedback I received from others pointed out, the physics in Unity compared to my Itch.io submission was completely different and felt terrible. Turns out that I was doing all my physics calculations in the Update function which threw all my calculations out of whack as WebGL's update must run at a different rate to Unity's. I did some research and found that when building for WebGL you should do all your physics calculations in the FixedUpdate function instead which would be fine except reading inputs in there is inaccurate and they can be skipped. In the end I used the Update function to store data about the users inputs (these were just simple boolean values for if a key was pressed that could be used in FixedUpdate) and fixed update to calculate everything which once I rebuilt worked! Everything matched what I experienced when testing in the launcher and it felt alright. Then I simply used the same ground detection in jumping to create wall jumping which applies force to the player in the opposite direction of the wall. 


That is as far as the player movement mechanics wise will go unless a crouch is added later and if that happens, a slide but I doubt there'd be much need for them (but they would be pretty fun :3).


And that brings us to the current movement system we have now which I will most likely improve when I have time in the future but for now that's all!