- Home /
Is it possible to have slow acceleration and high drag at the same time?
I'm working on a 2D sideview airplane game in the vein of Sopwith / Biplanes / Altitude, and I'm running into problems getting the movement right. Trying to achieve something similar to what you see in this video: https://www.youtube.com/watch?v=pUb2XsBl3Is
This should basically work as follows:
- As long as you're flying, you can rotate without any fishtailing (the plane always goes in the direction it's pointing and doesn't have momentum)
- Flying upwards slows you down, flying downwards speeds you up
- Once horizontal, you'll slowly return to your standard "default speed" if you gained/lost a lot of speed from ascending or descending.
- If your forward velocity drops too low, you stall. Once you stall, you start falling and need to point INTO the stall to recover.
I'm currently trying to use the physics system to get this feeling right, and I'm running into problems. Basically, if I want the steering to feel right, I have to put Drag very high. Unfortunately, this means that acceleration/deceleration is almost instant. If I put Drag low, I can get more of a feeling of keeping forward speed, but suddenly I feel like I'm sliding on ice (or playing Asteroids).
Here's the main movement code. Note that "acceleration" is actually just the force... the name is a bit misleading from earlier iterations working differently, and I haven't updatedit yet. Let me know if anything is unclear or if I can provide more information.
// Rotate based on player input
transform.Rotate(0, 0, inputX * turnSpeed);
// Get current forward speed for next round of calculations
forwardSpeed = transform.InverseTransformDirection(rb.velocity).x;
// STALL CODE
// If forward speed too low, stall
if (forwardSpeed < stallThreshold)
{
stalled = true;
stallText.SetActive(true);
rb.drag = 0f;
currentAccel = 0f;
}
else stalled = false;
// FLYING CODE
// If not stalled, start flying
if (!stalled)
{
// Turn off stall text
stallText.SetActive(false);
// Ramp to normal acceleration and drag
if (currentAccel < acceleration)
{
currentAccel += accelRampUp;
rb.drag += dragRampUp;
}
else
{
currentAccel = acceleration;
rb.drag = flyingDrag;
}
// Braking code
if (braking) // If the player is holding the brake button, start increasing the total brake power each tick
{
brakeAmount += brakePower*0.0001f; // Multiplier just makes the tunable value in the editor more readable
}
else brakeAmount = 0;
// Assign result of thrust + angle + braking to determine move amount
GetAngleSpeedModifier();
// Add force based on acceleration
rb.AddForce(transform.right *
(currentAccel
+ GetAngleSpeedModifier() // Modify accel by
- brakeAmount));