Sunday 19 January 2020

Hover? I Hardly Know 'Er! My First Actual Bit of Content!

Whammo!
Here it is! My first actual project-relevant post!
One of the first things I wanted to try out for this project was a way to design interesting yet realistic handling for the player's car. Obviously, I wanted it to be intuitive and fun for the player, as well as looking "realistic" and cinematic - two things which are often opposed.
The original Quarantine game was no help here, as it actually handles more like a real car. Allegedly, according to Ray Larabie, who worked on the game:
The original demo was done right about the time Wolfenstein 3D came out. There were some flat shaded polygon cars running around the streets but the poly count was limited for forty, Not enough for round wheels.[...] After we switch to sprite cars we were used to the idea of hovercars.
So despite having hovercoils instead of wheels, the car would only turn while moving forward or backward. The main difference was if you got hit, you'd pinball around a bit. I wanted to make a genuine "hovery" feel, and felt like that involved drifting, and even strafing, which would make hovercar combat significantly more fun.
There were three things I could see myself experimenting with:
  1. Physics-based force applied to the four corners of the car, mimicking the actual force that would be generated by the car's hover engines. I knew this would probably give me the most realistic effect, but was worried about the efficiency of using this en masse. More about this later.
  2. Wheel colliders, with "slippery" wheels. The nice thing about wheel colliders is that it emulates the shocks absorbing the car's shifting weight. I was hoping to basically make wheel colliders, but with invisible wheels, and give them very little friction to allow the car to slide laterally. This didn't work well, as the car still had to be moving for it to register any forces acting on it. I considered a few tank-type setups, using three wheels on a side, which allowed for turning of a dime but not sliding. Additionally, the more I looked at wheel colliders, the more finicky they seemed - there were a lot of variables involved that I didn't really grok. Additionally, I have the impression they wouldn't have been any more efficient than physics forces, ad they themselves use similar (or more) such forces. It's possible someone with a better understanding could have made this work, but it wasn't the right approach for a laymoron such as myself.
  3. Using an invisible, frictionless collider as a sled, with the car interpolating its rotation as the sled slides over uneven ground. I abandoned this idea without even experimenting because it seemed like it would never have worked for many reasons (if you've done this convincingly, change my mind!)
Ultimately I went with the first option. I followed a great tutorial by Claire Blackshaw to get the basics (and the test scene) established, then made a bunch of modifications to fit my needs. The most significant adjustment I made was that I found the car far too flighty, causing it to drift too much, and to flip too easily. I bumped up the car's mass and drag, which tightened the controls significantly, but the drag made it float like a feather when airborne. Since it's already detecting if its grounded or not, I set the car's mass to be basically nothing when the car is not grounded, so at any time, the car is either grounded, draggy, and easily controlled; or airborne and dragless.
I've also lowered the rigidbody's centre of gravity, which makes the car more stable and likely to stay upright. This is a bit of a tricky thing because if it's set too low, the car will try and stay level even when on inclined planes, and if it's not centred to the forces applied by the hovercoils, it'll list or flip very easily. I ultimately just added some code to set it to the average positions between the hovercoils.
As I mentioned, I feared this would be a performance problem if every NPC car used this system as well. My hope is that I can fudge NPC movement while they are idly moving about the city streets, only switching to full physics mode when attacked. That's a way off - stay tuned!

It still need some fine tuning to get things where I want them, but I think it's pretty good overall. One thing I'd like to experiment with is making adjustments to the centre of gravity as the car accelerates to accentuate the feeling of the car's weight shifting.
What does everyone think? Feel free to comment and let me know! Next post will probably be about a shader I made for the car. It probably won't be a terrible read!

What Else is New?

I've decided that I won't just concentrate on what I'm reading, and just kind of quickly chat about whatever comes to mind. This time though is about what I'm reading. I've just started Yoshiko, the third book in the X-Universe series, by Helge Kautz (and translated from German by Nathan Haines). It's based on a series of space trading sims I've been somewhat obsessed with for years, and I'm really glad the novels based on the games is finally being translated. The worldbuilding in the universe is really great, and the story is a lot of fun.

No comments:

Post a Comment