Floating and avoiding obstacles

Anyone have some ideas on best approaches to have like an underwater feel - where the enemies are kindof floating around with lots of movement, but not exactly sentient (e.g. not necessarily agents with a path to follow)

e.g. they could be like debris in the deep sea, but where there’s some random underwater current that changes organically and makes things move around in interesting patterns

Boids are cool but they are what you would consider agents:

If you want a cool bobbing motion that might look slick underwater, you could try something like this:

public class FloatBehavior : MonoBehaviour
{
    float originalY;

    public float floatStrength = 1; // You can change this in the Unity Editor to
                                    // change the range of y positions that are possible.

    void Start()
    {
        this.originalY = this.transform.position.y;
    }

    void Update()
    {
        transform.position = new Vector3(transform.position.x,
            originalY + ((float)Math.Sin(Time.time) * floatStrength),
            transform.position.z);
    }
}

Source: c# - How to animate objects with bobbing up and down motion in Unity? - Game Development Stack Exchange

You could even change the float strength based on other factors (underwater current etc).

1 Like