# Moving using rigidbody.MovePosition on grid

Hey! I just began using Astar so I am still really new to it. I was wondering if there was a way to use the example code in the getting started tutorial with rigidbody.MovePosition instead of character controller.

Sure.
Exact what to do depends on what effect that you want.
Exactly how do you want it to look? (realistic/not realistic, etc.)

I’m on my phone so I can’t post the code that I tried but ill do my best to describe the problem.

I replaced controller.simpleMove (dir) with rigidbody.MovePosition (dir). When I pressed play my gameobject just teleported to a completely different spot.

However if I do rigidbody.MovePosition (path.vectorPath [currentWaypoint]) it moves nicely across the path but too fast. If I try multiplying by time.deltaTime I get the same issue as above.

Any idea what could be wrong? Also thanks for the fast response!

Extra info: the game is in the x-y axis

You are confusing directions and points.
MovePosition takes a position, if you pass it “dir”, which is a direction, it will move to the wrong position. Giving it the next point in the path is great, but you cannot multiply it by delta time since that will just scale it towards the world origin, not really what you would want.

`
float t = 0…1;

float totLength = 0;
for (int i=0;i<path.vectorPath.Count-1;i++) {
totLength += Vector3.Distance (path.vectorPath[i],path.vectorPath[i+1]);
}
float target = totLength * t;
float c = 0;
for (int i=0;i<path.vectorPath.Count-1;i++) {
float dist = Vector3.Distance (path.vectorPath[i],path.vectorPath[i+1]);
if (c + dist > target) {
Vector3 targetPoint = Vector3.Lerp (path.vectorPath[i],path.vectorPath[i+1], (t-c/totLength)*(totLength)/dist);
//This is the interpolated point
break;
}
c += dist;
}`
You are looking for something like the above. It uses a variable t, between 0 and 1 to interpolate a point along the path.

Awesome! Thanks a lot for the help! Looking forward to dive into this when i get home from work!