Hello, I have a question about “Vector3.MoveTowards”
I’m trying to do something like after I click the mouse button the box will from current position and move to target position and the target position. The target position x I want every time I click the mouse button it will +10f there. below is my code:
public float characterMovmentSpeed;
public Vector3 targetposition;
public Vector3 currentPosition;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
move();
}
void move()
{
if (Input.GetMouseButtonDown(0))
{
float step = characterMovmentSpeed * Time.deltaTime;
currentPosition = this.transform.position;
targetposition.x = this.transform.position.x;
targetposition.y = this.transform.position.y;
targetposition.z = currentPosition.z + 10f;
this.transform.position = Vector3.MoveTowards(currentPosition, targetposition, step);
}
}
the result is the box just moves very very tiny something like 0.1somrthing.
do anyone have solution for it?
Many Thanks