Picking another object after deletion of currently selected instance?

Hello everyone!

In my game, I have a cow NPC, that upon getting hungry will search out grass to eat; problem is, that if the player picks up the grass the cow has selected, or if another cow eats the grass, the cow will still move towards the position of the grass; upon reaching its destination it just stands there.

Any help would be greatly appreciated!

1 Like

Option 1
Add to grass boolean variable to tag it either as free or taken
So when cow pick grass it can only look trough grasses? that are not tagged as taken
BUT that will not solve scenario if player gonna cut it
You could check if cow pos is same as target position
And if so and grass don’t exist order cow to pick another grass
OR if target pos and cow pos is the same but cow is not eating grass then search for another free grass
This way player can cut grass and other cow won’t eat each other grass

Option 2
Give cow timers
And make cows check every other sec if grass to which they travel still exist
If yes then keep going
If no then pick another random grass
Combine it with my idea of boolean variable for grass from above and you will get more natural cow AI

Option 3
Instead of cows eating grass that stands out
Create new object in place where cow eat grass which would be dirt circle of ground or something
Like in farming games when you can dig grass to create plot
We do not have grid of dirt plots and on top of it grass
We just have green color as ground
And whenever you dig we create dirt object and then turn it into grass
You could do the same and after some time simply remove that dirt object
And it would look like grass grow back

1 Like

I like the timer, I also love object linking.

Link the cow to the grass. When the grass is eaten before deleting it, pick the linked cows and then have them find new grass. This would address the current cow and other cows.

Boolean states can also help keep track of what the cows are doing.

1 Like

I’ll try this out, thanks!

The cow’s AI runs on a state machine, so the latter problem needn’t be attended to.

2 Likes

I just read what Keith wrote

His idea looks to me way better than mine
Object linking is also least performance hungry here