- Home /
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);
I need the slider to move the object forward and backward from its local position only, regardless of where it is in the scene.
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?
Basically I need something like this :
transform.position = transform.forward slider.value -2;
..but the thing is, this moves it to 0,0,0, in the world, then moves appropriately. Anyone?
Your answer
Follow this Question
Related Questions
Mathf.Lerp not working 2 Answers
How do I add multiple points using Lerp? 3 Answers
Add specific movement on double click 1 Answer
Lerp isn't completing itself 3 Answers
How do I translate around a circle? 3 Answers