Download

How to move an object to player

Hi peoples.
I thought I’d be able to figure this one out but apparently not. :stuck_out_tongue:
Basically I’m trying to get an object to float towards the player and then destroy its self when it reaches the player. Think of Crash Bandicoot collecting apples.
This is the blueprint I’ve made so far.
ac39a9cdbef136b1deadb1ba65db49fe0a46b010.png

The problem I’m having is that the object doesn’t move to the player, instead it moves away from the character to the same location each time.
I’m sure it’s probably really easy and I’m just missing something silly.

Anyone got any ideas?

Thanks!

I would guess you are not getting the right value for your player location. Putting a print screen node that prints the player location should help track this down.

You could try using “get player controller” or “get player pawn” and see if either of those works for you.

Hi Thanks for the response. I’ve added the Print String node before the Move Component To node and it displays my characters location but I’m not sure what to do with the location it returns. Also I just tried the Get Player Pawn which gives me the same result and if i use the Get Player Controller node the object slightly moves upward and then gets destroyed.
My current BP:
858148b5e920dd5f77c09b86cb00b28aca9fb534.png

Any other ideas? I’ll upload a video so you can see whats actually happening.

Here is a video:

Thankss!

Try it like this.

OnComponentBeginOverlap > Cast to “YourCharacter” > Move Component To > Destroy Actor

Hook the Other Actor from the Overlap to the Object on the cast. Then from the Return “As YourCharacter” pull out a Get actor location. Then do the Move Component To.

Hi, I’ve just tried and i still get the same result. Maybe I haven’t set it up properly?

Thanks.

How are the components set up on the apple actor? Is Apple the root component for the actor and is it Static or Moveable?

This is how its set up.


I’m not sure if I’m supposed to put a Scene component in there but without it I was unable to change the size of the trigger volume.

Try Plugging “Scene” into the Move Component instead of Apple, make sure Scene is “Moveable” as well. Alternatively you make Apple the Root Component

I think the problem must be the Move Component To node because if I use the Set World Location node instead, the apple snaps right to players location. Hmmmm I’m not sure what else to try.

Ahh DEDRICK that kind of worked. The Apple moves to the player but it only moves to the location of the character when the trigger was activated. I need the object to follow the character until it reaches the character before it disappears.

Any ideas?

Thanks!

It is because that node is only being triggered once on the overlap event.

For what you are wanting, you need to look into the “VinterpTo” node. This ‘pure’ node needs a companion “set world location” or other such node which would be fired on Tick and you need to use your begin/end overlap events to control it using a gate or some other logic.

For this you need to plug the AppleBP current location to current and the player location to target. Deltatime should come from your eventtick node and interpspeed you will want to mess around with.

That makes sense because it is a one time snapshot of the location. What Ryan suggested above should work but you will also need a way to kill the actor or it will move endlessly. Hooking a Destroy actor after Set World Location will kill it instantly. You will need a Branch and some logic to check the distance between current actor location and player so when it gets close enough it destroys itself.

Hi Thanks for the help its finally coming together. The only problem is like you say it won’t stop following me. This is what I have so far:
c0dc7a8409ac354867f1b713e2170ed3093fea5b.png

I’m trying to work out the distance between the character and the actor but it doesn’t seem to be working.

Actually It’s working. I just needed to set the over time to 0 and the interp speed to a higher value.

Thanks a lot, i would have probably been here for days trying to figure it out.

Cheers! :slight_smile:

FWIW, using the “move component to” node shouldn’t really be necessary with such a setup and may be costing extra. With 0 for time its basically a “set location” node anyways.

yay, victory~!

Ahh Thanks RyanB. Have sorted that!

I made a quick version for pickups for a prototype like this before, but I didn’t use the move component for it. I find it easier to use a basic lerp and timeline for something like this. You can also update it during the tick and interp toward the player but that doesn’t move over a specific time, so if you want to control time the lerp is better.

Because the player can move while we lerp it isn’t perfect but feel free to use it if you’d like. Here is what it looks like in action:

629929c6cdf583ad07a8305ae3b09d8ad7188d38.png

I have both the collision sphere and the static mesh collision set to overlap all and the sphere event kicks off to have it move to the player, once the static mesh overlaps the player or it finishes the timeline it destroys it and you would add to your points or inventory, etc.

I have an image of the the timeline attached, I just did an exaggerated ease in for it but you can set it up how ever you’d like and however long you want it.

*EDIT: Looks like you guys figured it out as I posted this! Haha, glad its working :smiley: