Move actor from one location to another

Hi!

If I now my actor’s location and the new location where I want to move it. In other words, if I know the start location and the end location, how can I move it?

I don’t want to teleport the actor instantaneously. I want to move it step by step: when the player press a key the actor will move a distance (I will decide the amount, the number of meters).

Maybe, it exists something to compute the path from one point to another, and set this path to an actor to move in.

By the way, the path will be a straight line without any obstacles between the two points.

Thanks.

I would suggest something like this Ue4 Tutorial - Moving an Object along a path using a Spline Track - YouTube, without the alpha thing. Instead, you would plug into the distance your variable that you would be modified in tick based on your MovementInput * Speed.

If you’re looking for full pathfinding, where you request the game move a character from point A to point B, and it finds a path for that (including dealing with obstacles along the way), what you want is the navigation system.

The path will be a straight line without any obstacles between the two points.

Then you could use this WTF Is? Interpolation - Vinterp Node in Unreal Engine 4 - YouTube and use Speed * {Your input axis} in place of speed

Thanks. This is what I need but I need to move with the mouse wheel. Any idea about how to do it?

Instead of using Delta Time I want to use mouse wheel events.

You can use the Input Action “Mouse Wheel Axis” or grab directly the pure function “Get Mouse Wheel Axis”.

image

Thanks but I’ve forgotten to mention: Instead of using Delta Time I want to use mouse wheel events.

Several ways to do this. Here are a few:

To start:
You can either setup an input action event for mouse wheel up and mouse wheel down in project settings under the input section. So that when you scroll up or down it will fire the designated events.

Or in the same section you can setup an input axis event where it creates an event that fires logic based off whether your mouse wheel moved in the positive direction or negative direction(Variable starts at 0 which is no input, 1 is up input, -1 is down input).

After that section:

On your player controller, character, or pawn you setup those events to be called and run your logic. For the scenario you described it sounds like you want the player’s movement to be a direction decided by the player and the distance moved decided by the developer.

Whenever the player wants to move, after they have determined their direction. Have the mouse wheel up or axis up fire off the event that moves the player x distance along the xyz direction determined by player(player forward vector), turn off gravity and physics while in movement, and keep other variables in mind to keep the distance exact.

Then you can do the same logic, except the direction reversed for moving backwards.

If you want to keep the player moving along the same path that they initiated instead of being able to change direction when they go backwards, you can create spline on initial movement that saves original location, next moved location, and all locations moved to. Your mouse wheel events can then be coded that when you scroll backwards it takes you to the last spline point, or last point the players was at.

Hopefully this helped. If you have any more question please describe a bit more in detail what you are trying to achieve for more specific answers.

EDIT: Also if you are looking for smooth movement along the spline and the distances are exact. You can setup an anim montage that syncs up with time it takes to move between points and play a standard ground forwardmovement animation.

Or if not using a spline. Simply set it up a root motion animation that goes specific amount of distance and animation playrate matches movement rate.

This can also be done using sequencer, create the walking sequence with time/movement matching distance and time moved. Play it every time the player moves.

1 Like

Say that you want to move your actor from World Location A to World Location B. The displacement vector from A to B is (B-A), obtained subtracting the A location from the B location. Now, you start in A. At every mouse wheel event you can add a portion of the (B-A) vector back to the previous interim location, until you arrive in B.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.