Devlog #4: Auto Landing System
In this post I'm going to discuss the vehicle’s auto landing system.
From the very first prototype of the game it was clear that being airborne would be something I needed to address. Even without a jump button, you could launch yourself into the air, lose control, and then stumble around for a while.
If you were in combat this meant you were dead -- you might as well just explode as soon as you go airborne, rather than stumble around while waiting to be obliterated.
Despite the obvious problems with being airborne, it was really fun to fly off cliffs and launch yourself off big jumps. The incentives were mixed though: you knew that landing probably wouldn’t go well, and therefore wouldn’t be fun, and that immediately afterward you’d die. You were giving up agency, which undermines the whole experience.
Since the first part of going airborne was so fun I didn’t want to cut it without trying to make it work. I started thinking about how the experience of being in the air could be fun and a way for better players to demonstrate their skill.
First, you had to be confident that your vehicle would land smoothly. I wanted you to be able to focus on playing the game. I didn’t want you trying to predict where your vehicle is going to land so you could align yourself to that surface orientation.
Second, you would need some mid-air control so you could still play while you’re up there, rather than just waiting to land.
In this post I’m going to focus on the first part: automatically landing smoothly so that going airborne does not completely kill your momentum. I’ll do more posts in the future on chaining moves, mid-air control, and mid-air aiming.
Initially, I started designing an auto-landing system that would be activated as soon as your vehicle went airborne. It had two functions: figure out where you were going to land, and then adjust your vehicle’s orientation in mid-air so that you landed as smoothly as possible.
When the vehicle takes off, I have its velocity, its position, and acceleration due to gravity. I want to know where it’s going to land, which will also helpfully tell me when it’s going to land.
To predict the vehicle’s landing location we can use a Projectile Motion equation. I can create a series of points along a curve which represents the vehicle’s airborne motion. As the time increases, gravity accelerates the locations toward the surface, creating a curve.
I generate this curve two points at a time in 60ms intervals. Originally I was only plotting a single point, and then doing a line trace straight down to check for the presence of a surface. If the surface was there, I would stop drawing points and pick that surface as the landing site.
Drawing two points allows me to draw the line trace from the first point to the next one, which gives a more accurate prediction, since the trace more closely resembles the vehicle’s trajectory.
There was a sneaky bug here that took a while to manifest itself. While driving across a slatted bridge, you could technically be airborne while your wheels were between slats. This would activate the auto lander, but your motion curve would extend below the bridge, through the slats. Eventually the curve would hit the surface below the bridge, which might be very different from the surface on the bridge. This could result in your vehicle suddenly pitching forward or backward to adapt to the surface in a very short timeframe.
For a while, I just thought that the wheel physics didn’t like interacting with the slats, until it occurred to me that I should turn on the auto lander’s debug output to see if there was anything unexpected happening.
I fixed this by doing a sweep trace from the vehicle’s location to the predicted surface location. If the vehicle couldn’t physically reach the predicted landing location, then it wasn’t a valid location, and it should either cancel the landing or use the obstruction as its landing site.
In any case, once I determined a valid landing location I also had the angle of that surface and, conveniently, the time until the vehicle would land there.
With the angle of the surface I could create a target orientation for the vehicle’s landing.
Then I could find the in-flight rotation the vehicle needed to apply, given its current orientation and angular velocity.
Lastly, I could use the predicted time until landing to evenly distribute this rotation across the vehicle’s flight path. This makes the automatic airborne rotation less jarring because the movement is consistent and sensible.
I made this system more accurate by having it make new predictions throughout the vehicle’s flight, so it can refine the accuracy of the landing site and the airborne adjustment.
A really nice bonus that I hadn’t planned on was how this system enabled new moves, like flip jumps, with minimal work on my part. I just had to tell the auto lander that the user wanted to flip, then add the number of flips times 360 degrees to the pitch angle difference. The vehicle’s angular velocity around its right vector would be increased to execute the right number of flips for the current jump.
This was cool because now you could dodge in three directions -- left, right, and up -- and attack enemies behind and below you.
That’s it for now. Thanks for reading!
King of Kalimpong
Multiplayer vehicle combat
Status | In development |
Author | piinecone |
Genre | Action |
Tags | Cute, Driving, Low-poly, Physics, Third-Person Shooter, Twin Stick Shooter |
More posts
- Devlog #5: Level Design and UI ProgressOct 04, 2021
- Devlog #3: Roundhouse KicksSep 17, 2021
- Devlog #2: Weapon BoostingSep 13, 2021
- Devlog #1: Speed, Level Design, and Camera BugsSep 09, 2021
Leave a comment
Log in with itch.io to leave a comment.