Move object back and forth to original position, with variables

Hi all

I’m working on a Blueprint on an Actor to get it to move back and forth on the X axis, and I want to make the move length and the move speed variable. This has been done.

The issue I have run into is that the actor does not always ‘reset’ at its original position - the end position changes based on the settings of my current Move Length variable.

My blueprints and timeline are attached.

What is a good way to ensure that no matter what I make the Move Length value, the object will always return at its original X axis value (and go no further back)? To illustrate what I mean, I have attached a screenshot of the actor -the red pen highlights where I want the actor to never go past. Therefore, Move Length should only determine how far the actor moves to the left, according to the perspective of the screenshot.

Thanks in advance for any assistance and please let me know if any clarification is needed on this question.

Cheers
Matt

I’d approach it like so for a rocking motion:

Image from Gyazo

1 Like

The -100 | 100 are offsets for the object’s original position. This will always be reliable.

Thanks for this! This helped a lot.

I have modified the Blueprint slightly and created variables so as to give control over the move length/end location and speed. If anyone is interested, attached are the blueprints and timeline.

If there is improvement opportunity for this code as well, please let me know.

Cheers
Matt

alt text