Goalkeeping AI!

Been trying for a couple of days to create a goalkeeper AI that tracks the position of the ball actor and moves along the goal line to get in the way of the ball. This is what i have at the minute, it works to an extent, but its slow and buggy. So i get the feeling there is a better way to do it.
Im pretty much out of ideas so i would appreciate some help, Thanks! :slight_smile:

What issues are you having with it. Without really knowing much beyond what you show it’s hard to help. One thing you might try is adjusting the amount of impulse based on the distance from the spot it needs to get to? Not sure what else to say without more information.

Is there a reason you want to use “Add Impulse” ? If you want more control over the actual position you could set the position directly and use FInterp to smooth the movement.

Don’t use GetAllActorOfClass each tick. Just use it when the ball is spawned e.g. on BeginPlay and store it for later usage. And is there a reason for a loop? Do you have multiple balls?

Shouldn’t you clamp the difference between the two x values? Or even better normalize it to something that scales with the size of the goal?

The y difference between the ball and the keeper should also have an effect of your keeper’s x position I guess.

The problems I am having are that the actor travels toward the ball but will sometimes continue to travel in that direction (even if i try clamping it) until it hits a wall despite the ball being in the other direction. Also it seems like if it hits a wall or any object in the scene it just stops working. When it does work it takes a long time to change direction. I have tried playing around with the Linear damping value but that just seems to hinder it movement even more.