# Unity, Player isnt following along the waypoints

I have a player with a Rigidbody, I want it to follow along the Waypoints, I have a script for it I tested it first on a Cube, everything worked fine, but on my character it just moves Towards the first waypoint then stays on the first waypoint instead of going ahead. Even if I comment out the LookAt Code section its not working. It could maybe cause the Y position of the waypoints that my player is stuttering, I changed it now. It is now moving along but stuttering much.

Here is a picture of the problem:

Here is my code:

public GameObject[] waypoints;

public float grindSpeed;
public float turnSpeed;

public int currentWaypoint;

private Animator anim;
private Rigidbody rb;

public bool isGrinding = false;

void Start()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody>();
}

void Update()
{
MoveAlongWaypoints();

if(isGrinding)
anim.SetBool ("isOnGrinding", true);
else if(!isGrinding)
anim.SetBool("isOnGrinding", false);
}

void MoveAlongWaypoints()
{
if(isGrinding)
{
//TRANSLATE
transform.position = Vector3.MoveTowards(transform.position, waypoints[currentWaypoint].transform.position, grindSpeed * Time.deltaTime);
//ROTATE
var rotation = Quaternion.LookRotation(waypoints[currentWaypoint].transform.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, turnSpeed * Time.deltaTime);

if(transform.position == waypoints[currentWaypoint].transform.position)
{
currentWaypoint++;
}
}
}

void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "GrindWayPoint")
{
Debug.Log ("Waypoint!!");
isGrinding = true;
}
}

• Be careful when mixing Rigidbody physics with direct transformation overrides. This rips control of the object's movement away from the physics engine, and can cause judder, weird collision behaviours, and even hamper performance (since the physics engine has to deal with out-of-band changes that are effectively teleports every time you move something without it). If you have a Rigidbody, route your movement through that, with velocity, AddForce, MovePosition, etc. – DMGregory Jan 25 '18 at 13:43
• I know but how I move the player along the waypoints with AddForce or MovePosition? Never did this before like that. – Daniel Jan 25 '18 at 15:33
• That sounds like something worth posting as a Question. ;) – DMGregory Jan 25 '18 at 16:21
• I concur with DM...if you are using the physics engine then move via forces. That's what it was made for. – Dunk Jan 25 '18 at 21:08

// These will probably never equal each other if(transform.position == waypoints[currentWaypoint].transform.position)
 if((Math.Abs(transform.position.x - waypoints[currentWaypoint].transform.position.x) < 0.01) && (Math.Abs(transform.position.y - waypoints[currentWaypoint].transform.position.y) < 0.01) && (Math.Abs(transform.position.z - waypoints[currentWaypoint].transform.position.z) < 0.01)) { //close enough...assume they are equal...so do some stuff currentWaypoint++; }