How do I make enemies move towards a random object?

Hi all.

I’m making a little farming game where you have to defend your crops from raccoons or they’ll eat them.
I’m trying to make them move towards a random soil object that doesn’t have the animation 0 (no crops).
So far I have tried:
Pick a random soil object, if its animation is not 0 move the raccoon toward it. But this made the raccoons really slow and jittery and wouldn’t stay on one soil patch.

I’ve also tried:
For each soil, if the animation is not 0 move the racoon towards it and it worked better but the raccoon speed increases with the amount of planetd crops you have which becomes unmanagable.

Is there a better way to do this? Thanks x

semi-code:

choose closet :herb:: too :raccoon: | use forces too position :raccoon: too, grass.X()\grass.Y()
:x: :herb: animation 0 |

Your original idea is correct, i would just make sure you use the link object actions after randomly picking a crop.

Then as a separate action, use the take linked objects into account condition, and out your move action in that. should do what you want.

Hi I tried playing around with your suggestion but I can’t seem to get it to work though it sounds like it should.

So I made a for each raccoon, pick a random soil, then if the soil has a crop on it, I’ve also tried adding a trigger once to it to see if it could make it work. Then if true link racoon and soil.

Then I tried to (in both sub, another event, and with for each racoon) take account all raccoons linked to a soil, then move racoon to soil.

None of those worked they either made the raccoons jittery, or they stopped movign altogether. Is there something I’m missing?

Are you using pathfinding for the racoons and how many racoons do you have at any points?

Too many objects with pathfinding will slow down the game and you may need to make it more manageable