Right now I’m working on something simple. I want an AI bug that will just fly around and avoid the player and colliding with the tileset, very much like this gif. I’m very new to gamedev and I’m finding it hard to discover any resources for programming a simple AI like this that doesn’t revolve around attacking the player or patrolling specific locations. I also assume that if I want to use more advanced AI later on, I’ll have to try and incorporate A* pathfinding into my platformer as most of the tutorials I’ve looked at point towards it.
Should I start with A* or try and find some method using colliders and raycasts to avoid my tileset? (My current attempts seem to get the AI either stuck or it just ignores the fact it’s supposed to move in the opposite direction to the tileset). If anyone has some advice or resources to direct me toward on how I should approach this, and potentially putting AI into other creatures as a beginner, I’d really appreciate the help!
If you only want your bug to avoid terrain, A* isn’t needed. You can probably steer the velocity away using front and side raycasts, like a roomba (cleaning robot). Or some other tricks (old games were usually ok with bugs going behind walls temporarily). I haven’t looked online, but maybe search for something like “fly steering algorithm”.
However if you want your bug to reach a specific destination (e.g. Follow player, or go to point X), then a pathfinder like A* will be needed.
Regarding the bug motion, the simplest might be to operate it in 2 steps.
Create 2 or 3 similar-looking looping animations of a transform moving in bug-like circles. Since you do them manually, it’s easy and gives you 100% control on the feel (different bugs can have different anims to suit their personality).
When your bugs spawn, assign them one of the looping anims. Have their transform follow the anim. If you feel fancy, you could try to slowly transition to a new one after X seconds, though this might not give nice-looking results (to be tested!) .
Now that your bugs move in idle loops, you can periodically (every 3s) move their “idle anchor” a few units away to give the idea that the bug explores the room. You can use raycasts or collider casts to know where your “idle anchor” is allowed to move, to avoid terrain.
Looking at the GIF you referenced, this might be exactly what they used.