SimpleMove and moving to a transform.position

Hiya,

Guess I am having a rough night tonight. :wink:

I have a GO that I want to use SimpleMove to move from the position it is at to a different position (primarily because that is what I am using for all my other movement). Thing is, I am having a problem in figuring out how to determine when I got to the end position. Here is a rough shot at the code:

		if (doAutoMove){
	
			gameObject.GetComponent(CharacterController).SimpleMove( transform.TransformDirection(Vector3.forward) * ( 40.0 * 1.0 ) );
			
			if (gameObject.transform.position == movePos2){
				doAutoMove = false;
				caller2.autoMoveComplete();
			}
	

		}

I looked into getting the distance but that didn’t seem like it was going to work and thought about Lerp but it wasn’t obvious to me on how to work that in either.

Any one have some ideas?

Thanks!

– Clint

You’re almost definitely overshooting the position, and == only returns true if the positions are EXACTLY the same. What’s wrong with the distance?

if (Vector3.Distance(gameObject.transform.position, movePos2) <= someTestValue){

where someTestValue is how “close” you need it to be at the end. if you do need to be in EXACTLY a given spot, when you’re in the close enough range, you can then manually set the position to the requisite one.

Hey StarManta!

Works great! I appreciate the help.

Regards,

– Clint