Hi peoples.
I thought I’d be able to figure this one out but apparently not.
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.
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.
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:
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.
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 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.
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 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.
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.
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:
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