I need help for smoothly moving my player from one location to another

Hey! I’ve been working on a fan blueprint that moves my player up(or down) based on the location of a scene component. It was working great at the start! I use a collision to detect when the player walks into the area, and once they do, the fan starts. To move the player I use a timeline and then I would just get the actor location when he entered, and lerp that to the scene component. My problem arose when I realized that the time to reach the scene component was the same regardless of the distance between them. And so I’m wondering how I can make the speed be the same, regardless of whether the scene component is high or low.

That’s how I get the delta time for the get float value :up_arrow:

And this is how I’m moving the player :up_arrow: :left_arrow:

Any help would be greatly appreciated! Thanks!

Hello Coen,

While this isn’t a question related to a course I think I can give you some hints as to what to do.

You’re correct that using both a loop and a timeline is going to result in variable speed based on the distance needed to travel. This is because you’re travel X distance over Y time, rather than just X distance at Y distance per time. Think traveling 10km or miles over 2 hours vs traveling that same distance but at 5km/miles per hour. In the example the result is the same, but now try adjusting the distance needed to travel.

There’s two ways I could tackle this problem depending on your project’s needs:

  1. Apply a constant force in the desired direction, either away from the fan or towards it. I would using the fan’s forward vector for this.
  2. If forces can’t be used (mainly because physics are not being simulated), then you can achieve the same thing by setting the players location manually similar to what you’re doing now. But rather than a timeline & lerp adjust the player’s location on tick by a set amount in a given direction (either away or towards) per second (hint: utilize delta time here). As with #1 utilize the forward vector of the fan to get the appropriate direction.

That should help you get to a solution for your problem.

What Tuomo said but also you can calculate the time. If you know the player movement speed and calculate the distance to the target, you can divide the distance by player speed and use in the lerp.

Thanks for the reply!

  1. I’ve never really done anything with physics in Ue5, but I played around with it yesterday. I used the add force node, and it seemed to work! Is that what you meant by stimulating physics?(I’ll be doing some more research later, becaus this is something new to me :slight_smile:)
    And then by using the forward vector, I could just times that by the use force node to go in the same direction. And I think a curve would work with this, because I could then times the product of above based on the time, that way it slows once the player get’s higher?
  2. And this will work because event tick goes on forever! After poking around a bit, I realized that I could probally get it working with event tick, but I thought that it might be more performant with a Timeline.

Hey, thanks for the reply! I’m a bit confused with the speed part though. Is it the max character movement speed?

Once again, thanks!

It is whatever you wish. Depends on the game. It could be from the movement component from your character or it could be something you apply to your pawn to get it to move.

Glad the force approach worked for you. For a steady speed, I would keep the movement tied to a fixed value rather than letting it vary with frame timing, and test it in a few different spots to make sure it feels consistent.

Thanks for stopping by! It’s been such a fun process of learning how to solve it! I’m going to share a video soon, because I’ve gotten so much help from this community :slight_smile:

One way to keep the speed constant with a timeline is to work backwards from distance: at the moment the player enters, compute duration = distance / desired speed, then feed that into the timeline (or set the timeline’s Play Rate to speed / distance if the track’s length is fixed). That way a tall fan and a short one both move the player at the same units-per-second instead of the same total time. Worth testing at a couple of heights to confirm it feels even.

Hey, thanks for the reply! Right now I’ve got it working by applying force to the character, and I ended up making the time into a variable, and so while it’s not perfect, it does get the job done!

But, it would be nice to polish it a bit more. I’ve been trying to wrap my mind around it, and I’ve got some questions. I do get how distance/speed = time! It’s really cool! If I wanted to move my character 30 in the z, I would just get the top divide that by 30, and I would get time, correct?

Question #1 :The timeline doesn’t fire every second, so if I’m moving 30 in the z, it would happen super quickly…so how does speed work with this? My character movement speed is constant, and the character wasn’t being applied a “speed”, it was just moving…

I’ve got some other questions, but the other ones also resolve around what “speed” is. I’m just a litte bit confused…:sweat_smile:. If you could help me out, or point me to some resources I could dig into, I would be soooooo grateful!

~Thanks!