How to make actor move back and forth

Hi :blush: ! I just started the Unreal blueprint course on udemy and am on the second game Crystal Cavern and started playing around a bit with what I’ve learned before building it, however, I ran into a problem:

What I want to happen:
I want a block to move in the same direction it is placed in the world and move back and forth to block the path of the ball (to always move in the block’s own x-direction).

What is happening:
The block only moves in the world x position, disregarding the angle of the block. I thought that if I used the relative locations/rotations I would not have this issue in the world. This seems like such a fundamental thing that I need to understand and would really appreciate the help.

See how it behaves here:
Kapture 2020-07-16 at 17.52.53

Blueprint for the block:

What I’ve tried:


Hi Kimy,

Here’s my implementation of what you’re trying to achieve.

There’s two things to note with mine (you can ignore the fact I used actor location instead of component relative location, this works with either):

  1. The X,Y,Z coordinates are like static positions on a grid and on their own are independent of rotation. What you need is the object’s forward vector, or effectively what the X-Axis would be after rotation is applied but expressed as X,Y,Z on that “static grid”. For example; if a rotation of 0-Degress would have a Forward Vector of (1,0,0), then a rotation of 90-Degress would change that forward vector to (0,1,0). A rotation of 45-degrees would be (0.5,0.5,0). You then add that forward to the current location of the actor you want to move, and you can increase the amount of movement by multiplying the forward vector by a float value (This is what the “movement speed” variable is doing).

  2. Rather than adjusting the location of the actor/component directly. The timeline is used to modify the direction of movement. Using the value of the float in the timeline as a multiplier to the forward vector of your actor/component. Positive values move forward, negative moves backward.

1 Like

Hi Tuomo, thanks a lot for the detailed answer, this really did what I wanted!

I played around with the forward vector after your explanation and came up with the following. However, not using delta time:

With this I noticed however how the box after a while had drifted away from the initial position, is this because the get world delta seconds is not using the tick rate of the system which according to google, seem to vary according to fps, or would it be to a rounding error?

Thanks again for your help :blush:

Delta Seconds is a representation of tick rate (it’s the same as the value that comes out of the Event Tick node) and is certainly related to fps. It’s useful because it smooths movement as tick-rate (and thus, fps) varies, and not using it can result in an object moving faster as fps goes up!

1 Like

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