In the last post I explained how I built the handling characteristics for my vehicles and the basic functions behind it. But these aren’t all of the functions involved in driving in my game. TE Offroad has a heavy emphasis on jumping and drifting, and would need more control available to the player. The next steps would be a useful handbrake and the ability to control the vehicle in air in order to land jumps rather than tumbling out of control.

First was the handbrake. It was extremely simple at first, basically just stopping all wheel spin on the rear wheels of the car. This does not have the same drag factor as the normal brake function discussed in the last post, rather the tires slide quite a bit on full lock. I wanted the handbrake to make it extremely easy to drift the trucks in a predictable manner. Only locking the rear wheels did not have very predictable behavior though, and initiating a drift by pressing the handbrake in a turn didn’t have much effect at all. Considering how I wanted the next function I would add to operate, I was able to use it’s basic principles to help turn the vehicle while handbraking. Unity has a very useful function called AddRelativeTorque that works perfectly for this. I updated the handbrake system so that pressing the handbrake button would lock the rear wheels, and if the button is pressed and the player also presses a turn button, a relative torque would be applied to spin the vehicle.

With the right amount of force applied, this worked excellently to initiate drifts while turning. Given the sliding tires didn’t slow down the vehicles too much, this system also really helped the player regain control without losing speed in various situations. While testing it, I realized it still worked quite well in mid-air. Almost an accidental feature but very useful for those smooth landings I want the player to pull off, or just to do spinning stunts. As a sidenote, after GTA V came out on PC it became a sort of milestone for me to compare my offroad handling against. With that in mind and my handbrake implemented, I hopped on the game wondering how their handbrake worked and experimented with their handbrake function in gameplay. Sure enough, and to my great surprise, if you hold the handbrake and steer while in the air, it will spin the vehicle. I can’t say for sure how they implemented their function, but the result is so similar I found myself a bit proud to have come up with a very similar system for drifting in my game without knowing these behaviors existed in GTA until after I had built my own system for it. I suppose it was a sign that I definitely was on the right track with how I was building my game.

The other thing I needed to add was the ability to control tilt and roll of the vehicle in midair, a feature that is visible and more common in games with vehicles and jumps lately. Since I was building this game for mobile, I started with the idea that tilting the phone would be a fun way to control the tilt of the vehicle. I later added the option to tie these controls to the UI buttons for the sake of playing the game while holding the phone in any position. Forward and backward tilt applied to the forward and backward throttle buttons, and left to right roll tied to the left and right steering buttons.

Too make this air-tilt control work as intended I needed to make sure it wasn’t active when the vehicle was still on or near the ground. This was a simple enough element to add, simply by casting a raycast of x distance down from the vehicle to check if it was too close to allow the tilt function to operate. The AddRelativeTorque function I mentioned earlier is what I used to control the tilt and roll. It works extremely well, allowing very subtle adjustments to the vehicle, or accelerating as it’s held down to allow flips and rolls before landing.

So after building a satisfying driving experience, and adding in these minor but majorly important air-tilt and handbrake functions, I could really put time into testing my prototype levels and refining how I would want the actual game aspects of TE Offroad to work. In the next post I will dive into how I decided to build the ‘game’ parts of my game, a time trial system akin to rally races, and a fuel run system utilizing the open world environments where the longest time racing wins.

Share this: Twitter

Facebook

Like this: Like Loading...