Confused on move actor to player

Hi,

I’m trying to make an object chase the player when they overlap a collision sphere on the object. Currently when I overlap with the object, the object will move to where the player initially spawned and not move to where the player currently is. Not sure what I’m doing wrong. In the screenshot, the player is controlling “BP_BALL”.

What’s inside that interface call?

Hey there @Daisyahoy! Welcome to the community! Is the interface just getting a reference to the player’s actor or something else?

Thank you for your response. Here is inside the interface call.

Tanks for your response, I think i just posted an answer for this on “ClockworkOcean”'s Post.

No :wink:

I mean, how does the other actor implement it?

Sorry, still a novice. My thought was that on the event it would call to the player ball to reference it for location data? Maybe I should make a new function in the interface that references “self” so that I can pull the location of the player?

If you don’t have some code on the other end of that interface call in the ball, then nothing happens. Which explains everything :wink:

What is the collision volume in, and is it the ball colliding?

Yes, the collision sphere is on the object, not the player.

So I should create a new function in the Int_Ball? What type of code would I put in that function that later can yield the location of the player ball?

Thank you for your help

You don’t need interfaces here, for now. It’s going to complicate things

On the overlap, you can just drag that ‘other actor’ pin and use GetActorLocation.

Ok, that worked. How would I filter this to only go to the player controlled pawn? New issue is that when multiple objects are near each other they will attack each other.

Thank you for the help.

So you can make sure it’s the player in one of these three ways. First one is called casting, and is the most expensive way, best used if you need to access player specific functions in a meaningful way. Second one is just checking it’s class is player and if true continue. You already had the tag way, you just have to remember to tag the player there.

That said, OnComponentBeginOverlap actually only fires once (When the overlap first occurs) so in your setup as it was it would only fire one time, so if the player moved, the enemy would move to the old location. You’re going to need to set a chasing bool somewhere and have it continuously update the location until the player get’s out of the collision.

Thanks @SupportiveEntity and @ClockworkOcean , my object is now on the move. New issue is that it seems to move to the original location my player spawns into and not to the current location of the player controlled pawn.

No worries, there’s a couple of issues here so let me run through them with you and the we can see if you really want to use the Move Component To node.

So first thing first, this is an async node (shown by the clock in the top right of the node) and that means it will run over multiple frames and only iterate the code after completed when it’s movement is done. Meaning you can only set it, and let it move to a location which if they are a player has likely changed in the meantime. How do we get around this? You could just have a stop passed in to this and pick a new location On Tick but that also has the issue of jittery movement because it’s not what this node is for, as well as their being a set time to movement. So no matter how far the player gets in your current set up it would only take 2 second to reach them. Either 100cm away or 1 million cm away would take 2 seconds.

Lastly and the most important, the location and rotation values in this node are Relative to this actor, not world space. This means that anything you pass in much be relative or you’ll get odd results. Example, if your player is at 100,0,0 and you pass in world location to this it will just move to it’s own forward 100cm, not to the player location. So to have this move to the player’s location you need to find it’s location relative to this one. So in the example before the player is at 100, 0, 0, world space right? So say if this component is at -100, 0, 0, we’d have to plug in 200, 0, 0, because it’s 200 away from the player in it’s relative.

Also Begin overlap only fires once while the player remains in the volume, so even if you pass in a new correct location, the node won’t fire again until the player leaves and reenters the volume.

All in all this node is not best suited for moving an AI to the player location constantly in a “chasing” manner. If you’re going to have an area that you could use navigation mesh on I’d recommend using the AI suite Unreal comes with to save you the headache so I’ll leave some tutorials for that below.

Disclaimer: One or more of these links are unaffiliated with Epic Games. Epic Games is not liable for anything that may occur outside of this Unreal Engine domain. Please exercise your best judgment when following links outside of the forums.

However if you would prefer to use that node for a specific reason, let me know here and I can see if I can hack something together for your use case.