Skip to main content
added 103 characters in body
Source Link
Dunk
  • 166
  • 5

Position is made up of floats. Most likely the 2 values in the ==this check never equal each other because of roundoff errors.:

// These will probably never equal each other if(transform.position == waypoints[currentWaypoint].transform.position)

When comparing floats you need to set some tolerance range to do the comparison and call it "good enough". e.g.   

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++; }

Position is made up of floats. Most likely the 2 values in the == check never equal each other because of roundoff errors. When comparing floats you need to set some tolerance range to do the comparison and call it "good enough". e.g.   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 }

Position is made up of floats. Most likely the 2 values in this check never equal each other because of roundoff errors:

// These will probably never equal each other if(transform.position == waypoints[currentWaypoint].transform.position)

When comparing floats you need to set some tolerance range to do the comparison and call it "good enough". e.g. 

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++; }

added 1 character in body
Source Link
Dunk
  • 166
  • 5

Position is made up of floats. Most likely the 2 values in the == check never equal each other because of roundoff errors. When comparing floats you need to set some tolerance range to do the comparison and call it "good enough". e.g. 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 }

Position is made up of floats. Most likely the 2 values in the == check never equal each other because of roundoff errors. When comparing floats you need to set some tolerance range to do the comparison and call it "good enough". e.g. 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 }

Position is made up of floats. Most likely the 2 values in the == check never equal each other because of roundoff errors. When comparing floats you need to set some tolerance range to do the comparison and call it "good enough". e.g. 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 }

Source Link
Dunk
  • 166
  • 5

Position is made up of floats. Most likely the 2 values in the == check never equal each other because of roundoff errors. When comparing floats you need to set some tolerance range to do the comparison and call it "good enough". e.g. 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 }