Best way to move an object to a specific location?

Hi everyone, I’m doing a little project and I’d like to start doing things properly straight away, so I’m asking for advice! I was wondering what is the best practice for moving an object x meters in a direction in y seconds? I would like the object to move in a straight line, and I’m referencing to it from the level blueprint

“set actor location” is the most straightforward method.you might want to also use a timeline.so you can easily set a wanted arriving time.

with set actor location i literally teleport the object, can i get a smooth movement by using the timeline?

Hey @FrankStifMaister!

Yes, you can do that!

  1. You right click on the graph and use “Add Timeline…” then double click the node to open it.

  2. Add a float track, and give it one keyframe with value 0 at time 0.

  3. Then, figure out how long you want the arrival to take, and at that time make another keyframe with value of 1.

  4. Exiting the timeline and going back to the event graph right click and get a “Lerp (Vector)” node.

  5. On the LERP, plug in your start at the top, your end on the second pin, and on the alpha pin drag out the timeline’s green float output into the Alpha.

  6. Put your timeline wherever you’d like, just not on tick. Use the “Play” input. You can also have it move to the starting location with reverse, if it’s not in the original location.

Let us know if you have any questions!

(post deleted by author)

That works very good, but i have a problem, i did this in a foreach cycle iterating an array of objects. but it’s like every “i++” in the cycle make my objects go farther.



Ohhhhh see, that’s important information.

Everything you did is exactly what was noted- but that’s for ONE object at a time, you can’t use a timeline with an array like that.

Have you tried using a regular ForEach loop instead of that custom one with delay? The problem is it’s moving on to the next element in the array before the timeline finishes.

ForEach isn’t “Do this to all at the same time” it’s “Do this For Each Element in order” so 1 does its thing, then 2 does its thing, then 3 does its thing.

Once the timeline is started, it just keeps going until the end regardless of the ForEach node.

You’re going to need to give each one of these geometries their own event. A timeline is a component, it can’t be reused in this way as you’re asking 1 component to govern multiple things at the same time using the same execution line and if you want them all to happen in tandem you’ll need to merge them into one actor and forego the ForEach.

Alternatively, make a “Moving Wall” Blueprint Actor, with a PUBLIC (eyeball open) Vector variable that once you drop it into the scene you can adjust that ending vector per actor in their Details tab on the level.

Then with “ForEach” you could have them all activate their own events using their own timelines.

Let us know what you’re feeling!

that works perfectly but I can’t figured out how timeline works, I thought that based on how I changed the curve of the timeline, the animation of the object would have a different effect, perhaps faster at the beginning and slower at the end, but I don’t think it works like that, or I’m doing something wrong, because I’m changing the curve in all ways and the animation result is always the same

It is correct,it works like this.

perhaps you could show the newest blueprint.so we can have a look.


This is my level blueprint where i call the custom event “Move”


here is my new blueprint with custom event “move” inside it, as you can see, i change the curve but the result doesn’t change

Edit: I’m dumb, i was modifying another timeline. It works fine, sorry but blueprint approach catches me off guard ahahah

2 Likes

I solved the problem (which wasn’t actually solved) by taking the actor’s position in begin play

WRONG WAY

RIGHT WAY