Blind Jam Dev Blog 003

WELP

So I added a new column to my Kanban project board: “Paused” – and that’s just what WWISE is for the moment. I have to spend a lot of time in WWISE to familiarize myself with it, and thats going to happen but in the meantime I wanted to get a few more things done.

One of those would be basic stellar bodies. The core of this game loop is navigating outer space 100% blind, via audio cues (and maybe haptics) only. I want a dynamic and reusable system for creating stellar bodies so when I get to map creation I essentially just have drag and drop prefabs to work with that will just work.

As a part of this stellar body work, I’m also working on the beginning of an astral gravity mechanic. It’s not going to be super realistic, but I want to add a bit of danger to compensate for – a light gravitational pull into stellar objects if you sit still near them too long.

I also wanted to overhaul the ship controls a bit, and migrate from using Translation to forces (for momentum and to play nicely with the gravity system I had started to develop thanks to a wonderful Brackey video)

    public void Attract(GameObject attracted)
    {
        Rigidbody attractedRb = attracted.gameObject.GetComponent<Rigidbody>();
        Vector3 direction = rb.position - attractedRb.position;
        float distance = direction.magnitude;

        float forceMagnitude = (rb.mass * attractedRb.mass) / Mathf.Pow(distance, 2);
        Vector3 force = direction.normalized * forceMagnitude;

        attractedRb.AddForce(force);
    }

I did alter it, as I didn’t want stellar bodies to attract one another – only the player. This is tied into a collider and rigidbody on an otherwise empty gameobject just for the purposes of defining a bodies gravity well.

So now that I’m using forces for this, I need to adapt my ship motion to use forces too (as well as add a damping effect since drag seem to only work when you use native gravity).

    private void Movement()
    {
        var movementInput = controls.PlayerController.Movement.ReadValue<Vector2>();
        var movementRotation = controls.PlayerController.Heading.ReadValue<float>();
        var movementBoost = controls.PlayerController.Boost.ReadValue<float>();

        var movement = new Vector3
        {
            x = movementInput.x,
            y = movementInput.y
        }.normalized;

        // Rotate
        if (movementRotation < 0)
        {
            rb.AddRelativeTorque(Vector3.forward * torque);
        } else if (movementRotation > 0)
        {
            rb.AddRelativeTorque(Vector3.back * torque);
        }

        // Strafe
        if (movement.x < 0)
        {
            rb.AddRelativeForce(Vector3.left * thrust);
        } else if (movement.x > 0)
        {
            rb.AddRelativeForce(Vector3.right * thrust);
        }


        // Forward/Backward
        if (movement.y > 0 || movement.y < 0)
        {
            // ugh a float that is only 0 or 1, how annoying
            // boosting
            if (movementBoost < 0.5)
            {
                maxThrust = standardMaxThrust;
            }
            else
            {
                thrust = boostSpeed;
                maxThrust = boostSpeed;
            }

            rb.AddRelativeForce(Vector3.up * thrust * movement.y);

            if (thrust <= maxThrust)
            {
                thrust *= accelSpeed;
                glide = thrust;
            }
        }
        else
        {
            thrust = baseThrust;
            glide *= .799f;
            rb.AddRelativeForce(Vector3.up * glide);
        }
    }

There’s a lot going on here. I’m extracting some values from the InputSystem (which I need to learn how to use better because these are all just configured as buttons, not even using their easing or other modes), and normalizing my 2D movement vector.

I process rotation first since all the other forces use the ships heading. You may notice both strafe and rotation are broken out, since both were being problematic for one liners. I simply didn’t know a simpler solution than the if block.

Forward/backward thrust is where things start to get interesting. Im first processing boost, which jumps you straight to a higher max thrust. Then we process the thrust force and increase it a little if we aren’t at max thrust. And finally we process the glide a bit which gives you an easing out of speed.

There are starting to be a lot of settings…


None of this is very elegant, but it was starting to feel pretty ok. With these changes came a complete overhaul of the stellar body gravity too.

    public void Attract(GameObject attracted)
    {
        Rigidbody attractedRb = attracted.gameObject.GetComponent<Rigidbody>();
        Vector3 direction = rb.position - attractedRb.position;

        // modifiy the gravity origin to the surface of the planet (hopefully)
        var radius = (surface.radius / 2);
        var mult = (transform.localScale.x * transform.localScale.y * transform.localScale.z) / 3;
        radius *= mult;

        float distance = direction.magnitude;

        float forceMagnitude = (rb.mass * attractedRb.mass) / Mathf.Pow(distance, 2);
        Vector3 force = direction.normalized * forceMagnitude * MagnitudeModifier();
        if (force.magnitude > 1000)
        {
            if (force.magnitude > 7000)
            {
                force = direction.normalized * 7000;
            }

            string text = "Magnitude: " + force.magnitude;
            Debug.Log(text);
        }

        attractedRb.AddForce(force);
    }

    float MagnitudeModifier()
    {
        switch (MassType)
        {
            case Type.Asteroid:
                return 1;
            case Type.Planet:
                return 1000;
            case Type.Star:
                return 10000;
            default:
                return 1;
        }
    }

I went a little nuts trying to find a good point between REALLY FEELING a planet pulling you in (which usually led to it being so powerful you couldn’t escape) and it being more of a curiosity than a threat. I still haven’t found that point, and I need to tune this script up so I can do more on-the-fly tuning to find a better niche. This is a core part of gameplay, so some Handles and labels may get involved for editing planetary gravity well power/size.

So now, while imperfect, I have a movement system (complete with speed lines for my dev reference, that won’t be in the final game since there won’t be any appreciable grapics). This meant some issues on kanban got closed, and WWISE is dredged back up. I can’t put it off any longer, it’s time to get to learning WWISE.

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *