Dev Diary - Barnstorming Remake: Player Controller


Look at the way the car moves in the 2 gifs above. The first gets a direct input from the keyboard, getting a value or -1, 0 or 1. It applies that to the z velocity to create snappy movement. The second gif, shows using Input.GetAxis("Vertical") and applying that to the z velocity. This creates the sense that the car is heavy and takes time to build up speed.

I went with the first one though, because as much as anyone would like their games to feel "realistic", you need to decide what is best in creating the experience. Barnstorming is a fast paced, tactile, "arcade" game. Players need direct input on where they will move and when. 

Once the input is saved as a float, it calls the MoveVertically function. This takes that direction and applies it to the car's rigidbody. There are other ways movement could be done. Adding force is an option, yet it would be even more floaty than the 2nd gif up top. Altering the transform directly would be a faster way to do things, yet since we are using the physics system and colliding with things is an importand aspect of the game, we need to use a rigidbody function.

For accelerating and decelerating, the only input read is the spacebar. If it's pressed, then the Accelerate function is called. If it is released, then the Decelerate function is called.

All this does, is move the x velocity of the car up to the max speed or down to the min speed over the duration of timeToMaxSpeed or timeToMinspeed. I tried using Mathf.Lerp instead of Mathf.MoveTowards, yet lerping it would result in problems of the car not entirely reachig the max speed.


The most complex system in the player control is certainly the knockback. When the player collides with a solid obstacle, the Knockback function is called.

It first checks whether or not we are already being knocked back. If not, then we disable all control of the car and stop it from moving forward.

Then the coroutine KnockbackPush is called. This moves the car backwards until the distance between the car and the hit position exceeds the knockbackDistance.

Then after that is all done, we wait half a second before allowing the player to regain control of the car. This is so that the player can't move the car up and down while it's basically stationary. It looks weird and ruins the illusion that the car is actually moving.


When the car hits a pothole the Slowdown function gets called. All it does is first make sure that the car is not knocking back, before setting the horizontal velocity to close to 0. If this knockback check wasn't there, then if we were to slow down while knocking back, the car wouldn't move at all. It would be stuck.