Need Help with the enemy ai for my game(it's probably simpler than I think)

Godot Version

4.2.1

Question

I have a 2d game where you spawn and raise birds which are called “birbs” (I know, soo unique) And enemies called MiniBats try and eat them. I need to come up with a system where either A, they lock in on and go to the nearest birb, Or B the birb they chase is randomly selected. Whichever one seems easier, help would be greatly appreciated.

Didn’t this just get solved?

How is your issue different from your previous topic?

I came up with another idea halfway through too see which one seems more reasonable

I’m not sure I know what you mean.

If you have a question after being unable to solve the problem, please post your question below.

Well the first solution seemed to work in theory, but not in practice and so I thought, hey maybe there’s a simpler way to do this which is just picking a random birb. Thats why I made this to A get the first one fixed or C figure out how to patch together the second one. If you like, I could post the birbs finished AI and the Minibat nodes here.

By C I meant B

I should probably get rid of the solved mark on the other post to clear up confusion.

Definitely. Marking the subject as solved when you know it isn’t is very misleading. There’s also no need to create a new topic just to prompt the forum to answer a variation of the same question. If you were unhappy with the solution we provided in the previous post you should’ve just said so. We would have tried to help you arrive at a solution you’re happy with.

On a more personal note, it doesn’t look like you’re thinking about your issue for more than a few minutes. Programming is not always simple and easy. Lots of problems can take days to solve - even if they are simple in concept. If you’re impatient and unwilling to think about the problem on your own, that’s just outsourcing your work to the community.

Use the great resources that are available on the internet to learn programming and get familiar with Godot as a whole.

Well, at this point going to the community is my last resort. I’ve looked at tutorials coded my own things mixed the two together and none have worked for my purposes, if they worked at all.

Fair enough. But it’s hard to help you with the way you’re conducting yourself.

Maybe you could explain why your previous solution doesn’t work for you anymore.

It has to do with the birbs constantly spawning in different places or dying. I have to find away for the bats to keep track of them all. That is the part I could never figure out. Every other aspect of the game hinges on the bats functioning properly which is why I want to code them as soon as possible.

Alright. There’s a simple way to keep track of specific instance(s) without the need to do it manually (e.g. by adding/removing instance in an array).
I’m talking about using groups.

Using groups

For each node, one or more groups can be assigned.
When making a script, you can use the following code to retrieve all nodes within a specific group.

var birbs = get_tree().get_nodes_in_group("birbs")

All you have to remember is to assign the birbs group to your birb-scene

This hopefully solves your problem.

Thank you so much!!!

1 Like

You’re welcome.

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