Looking for Drag

Given the code:

using UnityEngine;

public class LevelControl : MonoBehaviour
{
    [Tooltip("% Earth Standard Gravity")]
    [SerializeField] float gravityFactor = 0.167f;  // initialize to Luna's gravity

    [Tooltip("1 = 1 standard atmospher")]
    [SerializeField] float atmosphericDensity = 0.000001f;

    const float atmosphericDrag = 2f;       // amount of drag at 1 standard atmosphere
    const float standardGravity = -9.81f;   // 1 standard Earth Gravity

    private void Start()
    {
        Physics.gravity = Vector3.down * (gravityFactor * standardGravity);
    }

    public float GetDrag() { return atmosphericDensity * atmosphericDrag; }

}

I need to find the correct number for the atmosphericDrag. Any suggestions?

Hi,

What’s “correct”? Maybe this article will help.

Unity’s Rigidbody component has got a property called drag. Have you already looked it up in the Unity manual and read its description?

Thanks for the reply @Nina, unfortunately, that didn’t give me any more of an idea than any of the other articles I’ve looked at, although it did show the math in a much clearer manner. And yes, I did look at the documentation, fantastic description of what it does… not so much concerning how it relates to real-world numbers. The consensus I’ve found seems to be “Play with the number until you find something that feels right and don’t worry about the how.” So its likely I’ll have to just build a few levels and play with the code to get something that “feels” right.

Here is how I’m using the function for those who are curious:

using UnityEngine;

public class PlayerMover : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        shipRigidbody = GetComponent<Rigidbody>();
        shipRigidbody.drag = levelObject.GetComponent<LevelControl>().GetDrag();
    }

Unity is not the real world. In fact, if we try to copy the real world, our games often end up looking and feeling fake. A common example is a “realistic” jumping behaviour in platformers. For this reason, it is common practice to tweak the values until one is happy with the result.

I mentioned Unity’s drag because the Unity programmers took the atmospheric drag into consideration. If you implement your own “atmospheric drag” feature on top of it, you might get unexpected results. The default value 1 probably refers to the standard atmosphere.

After playing around a bit while trying to fix a different issue, I’ve realized that Unity’s Physics Engine is not working the way it needs to for my game. Looks like it’s time to revisit one of @ben’s earliest courses and write my own.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms