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?