I found this video several days ago, and I don’t know how is it possible. I can write simple AI like being able to patrol to random points in a circle, start chasing, and even some extras like jumping or charging towards player. But I don’t know how to do with a 2D game like moving not in a straight line but with curves, start moving around player and go closer to attack, move back a little after, and so on. Or on patrol not moving to random points, but to smoothly wondering around the area, with smooth turns and stuff. This is math, I know that. But have no idea how to achive this. Basicly what’s in that video. How can I learn stuff like this. If I don’t know what kind of math used to achive this, can I still learn it? (My math knowledge not the best). Or should I switch from porgramming if I don’t know even this by myself? Can someone give me links, tips about these stuff?
Thank you!
Let me get a few things out of the way. You can still learn anything if you are willing to put in the time. So done give up just because something seems frightening at first. Divide and Conquer! If some large task seems too complicated, split it into smaller problems and work on solving these, potentially by further dividing them.
I never implemented enemy AI myself, so take the following with a grain of salt. But:
To have move control over complex behavior, look into statemachines. This gives you more control over defining what can happen in what situation / state. Like, while they are in combat mode, they wont wander around but instead either chase or attack the player. Stuff like that.
There are several different ways to implement anything. Not just one. Take the “smooth turns” as an example. You could do it several ways. By only having them move forward / backwards, and being able to turn, for example, you would achieve smoother motions. Or you could generate a path of points they are walking along, and generate these turns into the path itself. Any idea you may have can work. There is no “one right solution”, just varying degrees of appropritate (good to bad) depending on the context, ie the game.
To stop them from flocking together, he casts a couple rays outwards in front of each enemies. This is visualized at 16 seconds and following. He also mentioned that he was inspired by the Boids. So if you want to get a rough idea on that, i would recommend looking at the Boids video of Sebastian Lague. He does a great job breaking down and explaining potentially complex topics.
I know some will disagree, but Math is not that important in programming. It helps, sure. But programming is more about problem solving skills. Thinking logically, algorithmically. Divide and Conquer. Splitting something complex into more reasonable part-problems you are able to solve. Some problems will, of course, involve math. Especially vector math can be helpful in gamedevelopment. The same goes for some trigonometry and other involved topics. But generally speaking, you should rather work on getting to the point of being able to identify what you need (ie coming up with a solution / approach, Divide & Conquer). Then you can simply look up the involved math.
So should you switch from programming? Nobody can answer that question other than yourself. Is it fun to you? Is it something you like spending time on? Do you mind investing the time to get better at it? Or do you see it as a burden as soon as you cant do something without putting some time into coming up with a solution?
Only you know these answers!
As for links, the above mentioned Sebastian Lague did a tutorial series which is great for programming beginners, but you said you already know the basics. So at that point it really is more about identifying problems you see (or setting goals) and figuring out what you need to accomplish them. Then looking up the required information, or looking for how others implemented it. Be aware that you will likely never find exactly what you are looking for. Thats why Divide and Conquer is so important. If your question is still “how do i make enemies avoid each other exactly as i see it in this video”, then finding an answer can be hard or even impossible. But if you already broke it down to several smaller problems, one of which may be “how to avoid boids bumping into each other”, then thats something you can easily google for. And once you solved all these smaller problems you can stitch it together to what you originally wanted to achieve.
I hope this helps