Moving along a local axis with a slider..

I am trying to move an object only in its forward direction a set amount. I have a slider that I want the player to pull down and in turn the object on screen moves back in its forward direction. The player can also rotate the object left and right with a different slider, but that one works fine.

This works but only if the object stays rotated in the same direction :
vartargetPos = newVector3(transform.position.x, transform.position.y, startPos.z - (slider.value * 2));
transform.position = Vector3.Lerp(transform.position, targetPos, Time.deltaTime * 10);

This works, but snaps the object back to 0 in the world space for the z axis when I use the slider :
vartargetPos = Vector3.forward * slider.value;
transform.localPosition = Vector3.Lerp(transform.localPosition, targetPos, Time.deltaTime * 10);

There are a few other things I’ve tried but they are all pretty similar to this. Any idea where I am going wrong here?

As I continue to mess with it I feel like it should be something as simple and similar to this…

transform.position = transform.forward * slider.value * 2;

but without placing the object back to 0,0,0 in the world space.

I am still struggling with this for some reason … I’ve attached an image to try and help explain.

More or less I just need to know where I am going wrong in making my game object move in its forward axis a fixed amount. I need this movement to work regardless of where in the scene the game object is.

I think you were close, maybe this?

transform.position += (transform.forward.normalized * -1) * sliderValue

the * -1 is just to convert ‘forward’ to ‘back’