Monday, May 29, 2017

Stopping Power

Part of actually changing gameplay means I get to put puns in the blog titles.

Not a lot changes in this update, but I did act on the feedback I got last week. I changed the orientation of some obstacles in one level to make the solution to that level more intuitive, and I spent a lot of time looking at how I move the player and eventually came upon what I think is the best way to force the player to stop when they let go of inputs.

I tried at first to make acceleration and deceleration be dependent upon time rather than the drag setting on the player's rigidbody, then I briefly considered overhauling how the player moves entirely, but I eventually decided I would limit the player's speed by modifying the rigidbody's velocity directly, which is what I already do in several parts of the game.

The next hurdle was figuring out under what conditions to have the game stop the player. Obviously, when the player isn't entering any input, I need to stop them, but how to detect that got a little fiddly. I use Input.GetAxis() instead of Input.GetAxisRaw(), which means that there's a substantial amount of time where input is "falling off" after you let go of whatever keyboard key you're holding down. I tried a bunch of workarounds until I figured out Unity already had this solved with the Input.GetAny() method.

After I got everything working, I realized that modifying the rigidbody's velocity directly worked, but didn't feel right. Everything was too stiff, it almost gave you an anxious feeling. So I created a drag setting that exists solely for slowing down the player, and now when I want to slow the player, I just set their drag to that number. It seems to work a lot better, and I have a lot of freedom over how stong I want the stopping power of that function to be. Which brings us back to the title of this blog post. Full circle!

P.S. This update caused several bugs, including one which limits your speed if you charge while standing still. I've fixed most of them already, but as this is already a late update, those fixes will be coming next week.

Charging-up sound effect is by Javier Zumer. I use and modify it under this license.

No comments:

Post a Comment