# How to get this object to move

I’m having a method in C# that finds the position of the player and the end position. The object jumps to the right position, but I would like the object to “walk” there over a period of time. How do I do that?

The code that actually moves the player is
`player.transform.position = Vector3.Lerp(playerPos,endPos, Mathf.SmoothStep(0.0f, 1.0f, 1.0f));`

I’ve also tried to rotate this object towards this coordinate, but it doesn’t rotate all the way towards it.

The code snippet I used for that is
`player.transform.rotation = Quaternion.Slerp(player.transform.rotation, Quaternion.LookRotation(endPos), rotationSpeed * Time.deltaTime);`

Here’s my code:

``````public Vector3 MoveToCoordinate(int[] matrix)
{
int x_pos = (int)(matrix * square[0,0].getMWidth());
int z_pos = (int)(matrix * square[0,0].getMLength());

x_pos +=(int)square[0,0].getMWidth()/2;
z_pos +=(int)square[0,0].getMLength()/2;

Vector3 playerPos = player.transform.position;
Vector3 endPos = new Vector3(x_pos,0,z_pos);

WalkToCoordinate(playerPos, endPos);

player.transform.position = Vector3.Lerp(playerPos,endPos, Mathf.SmoothStep(0.0f, 1.0f, 1.0f));

return endPos;
}
``````

Appriciate all the comments so far, thanks.

To make things more clear, I’m posting more of my code.

Here is my Update() method:

``````void Update () {

if(counter == 0)
{
counter++;
getObject();
}
if(move)
{
WalkToCoordinate(startPos, endPos);
}
}
``````

The player is set to move once the dice is ready, this bool is not set to false again, since I don’t know how this object can report that it has arrived at its destination.
This is the WalkToCoordinate method:

``````public void WalkToCoordinate(Vector3 startPos1, Vector3 endPos1)
{
int rotationSpeed =15;
int moveSpeed = 1;
Debug.DrawLine(startPos1, endPos1, Color.magenta);
Vector3 moving = endPos1;

Transform goTransform = this.GetComponent<Transform>();

//Look at square
player.transform.rotation = Quaternion.Slerp(player.transform.rotation, Quaternion.LookRotation(endPos1), rotationSpeed * Time.deltaTime);

//Move towards target
player.transform.position = Vector3.Lerp(startPos, endPos, Mathf.SmoothStep(0.0f, 1.0f, 1.0f));

//move = false;
}
``````

I don’t understand how to make this object move in a linear space to the given coordinate, and then return something when it has arrived.

Ok, now I think I see the problem. You are using the “Lerp” method, but you’re essentially telling it to instantly jump to the end position. There are three things you need to do to accomplish your goal:

1. Instead of passing SmoothStep to your Lerp, pass Time.deltaTime. You can multiply it by a factor to change the movement if you like – just keep the factor constant.
2. Make sure that “startPos” represents the player’s position for each call to Lerp(). You can do this by grabbing the transform’s position each time, if you want.
3. To find out when you’re done, you can compare the player’s current position with the end position, and either see if it is equal (not sure if this will work exactly), or see if it’s “close enough,” using a distance.

There may be more efficient ways to do this, and maybe others can pipe in if this is the case.

If you need specific help on any of these steps, let me know; I’ll be glad to explain further. Good luck!