AIController.determineDirectionChange C# (CSharp) Method

determineDirectionChange() protected method

protected determineDirectionChange ( Vector3 npcPosition, Vector3 newPosition ) : void
npcPosition Vector3
newPosition Vector3
return void
	protected void determineDirectionChange (Vector3 npcPosition, Vector3 newPosition)
	{
		// Translate the new position to compare against the origin (easier)
		Vector3 biasPosition = new Vector3 (newPosition.x - npcPosition.x, newPosition.y - npcPosition.y);
		// Compute the tangent of the new position to compare for angles
		float biasTan = (Mathf.Abs (biasPosition.y) / Mathf.Abs (biasPosition.x));

		/*
		if (biasPosition.x > 0) {
			lastDirectionWasRight = true;
			flipXScale (true);
		} else if (biasPosition.x < 0) {
			lastDirectionWasRight = false;
			flipXScale (false);
		} else if (lastDirectionWasRight) {
			flipXScale (true);
		} else {
			flipXScale (false);
		}
		//*/

		if (Mathf.Abs(biasPosition.x) < directionThreshold && Mathf.Abs(biasPosition.y) < directionThreshold)
		{
			if (lastDirectionWasRight)
			{
				setAnimatorInteger((int)WalkingDirection.STILL_DOWN_RIGHT);
			}
			else
			{
				setAnimatorInteger((int)WalkingDirection.STILL_DOWN_LEFT);
			}
		}
		else if (biasPosition.x >= 0 && biasPosition.y >= 0) {
			// Quadrant 1
			lastDirectionWasRight = true;
			setAnimatorInteger((int)WalkingDirection.MOVING_UP_RIGHT);
			testDirectionChange (biasTan, NPCDirection.R, NPCDirection.TR, NPCDirection.T);
		} else if (biasPosition.x < 0 && biasPosition.y >= 0) {
			// Quadrant 2
			lastDirectionWasRight = false;
			setAnimatorInteger((int)WalkingDirection.MOVING_UP_LEFT);
			testDirectionChange (biasTan, NPCDirection.L, NPCDirection.TL, NPCDirection.T);
		} else if (biasPosition.x < 0 && biasPosition.y < 0) {
			// Quadrant 3
			lastDirectionWasRight = false;
			setAnimatorInteger((int)WalkingDirection.MOVING_DOWN_LEFT);
			testDirectionChange (biasTan, NPCDirection.L, NPCDirection.BL, NPCDirection.B);
		} else {
			// Quadrant 4
			lastDirectionWasRight = true;
			setAnimatorInteger((int)WalkingDirection.MOVING_DOWN_RIGHT);
			testDirectionChange (biasTan, NPCDirection.R, NPCDirection.BR, NPCDirection.B);
		}
	}