Rotating the Correct Direction with Rays

So I am creating a gameObject that can move around and turn when it sees another gameObject. In order to give my gameObject vision, I attached a list of rays to the gameObject to act like its eyes and use raycast to determine if an object is in front on it. The problem I am facing is getting my gameObject to rotate the correct direction. When the game first runs and my object is going forward, my gameObject’s vision works fine and it can rotate the correct direction. However, once my gameObject is facing a different direction, that’s when it rotates the wrong way.

public void Touch(Creature aCreature){
		RaycastHit hit;
		for(int count = 0; count < aCreature.rays.Count; count++){
			if(Physics.Raycast(aCreature.rays[count].origin, aCreature.rays[count].direction, out hit, 1f)){
				// Checks to see if the creature is facing forward or right, if not it's facing back or left
				if(aCreature.rays[count].direction.x <= aCreature.creature.transform.forward.x && aCreature.rays[count].direction.z >= aCreature.creature.transform.forward.z){
					aCreature.creature.transform.Rotate (0f, 0.5f, 0f);
					aCreature.speed = new Vector3(0.1f, 0f, 0.1f);
				}
				else if(aCreature.rays[count].direction.x <= aCreature.creature.transform.forward.x && aCreature.rays[count].direction.z <= aCreature.creature.transform.forward.z){
					aCreature.creature.transform.Rotate (0f, 0.5f, 0f);
					aCreature.speed = new Vector3(-0.1f, 0f, -0.1f);
				}
				else if(aCreature.rays[count].direction.x >= aCreature.creature.transform.forward.x && aCreature.rays[count].direction.z >= aCreature.creature.transform.forward.z){
					aCreature.creature.transform.Rotate (0f, -0.5f, 0f);
					aCreature.speed = new Vector3(-0.1f, 0f, 0.1f);
				}
				else{
					aCreature.creature.transform.Rotate (0f, -0.5f, 0f);
					aCreature.speed = new Vector3(0.1f, 0f, -0.1f);
				}

				aCreature.rays.Clear ();
				objects.Vision (aCreature);
			}
		}
	}

I think that the main reason why my gameObject rotates the wrong way is because once my object rotates the location of where each ray is is constantly changing and is too difficult to predict every time. Is there a method in Unity I can use to have my gameObject rotate in the correct direction no matter what direction it’s facing?

So I changed my code a little. I created 2 lists to hold the rays on the left and right side of the object, so it’s easier to determine which side of the gameObject the other objects are. The problem now is trying to make the gameObject move in the right direction. Is there an easier way to have the gameObject move the direction it’s facing?

public void Touch(Creature aCreature){
		RaycastHit hit;
		for(int count = 0; count < aCreature.leftRays.Count; count++){
			if(Physics.Raycast(aCreature.leftRays[count].origin, aCreature.leftRays[count].direction, out hit, 1f)){
				aCreature.creature.transform.rotation = Quaternion.LookRotation(Vector3.RotateTowards(aCreature.creature.transform.forward, aCreature.creature.transform.right, Random.Range(0f, 5f), 0f), Vector3.zero);
				aCreature.leftRays.Clear ();
				aCreature.rightRays.Clear ();
				objects.Vision (aCreature);
			}
		}
		for(int count = 0; count < aCreature.rightRays.Count; count++){
			if(Physics.Raycast(aCreature.rightRays[count].origin, aCreature.rightRays[count].direction, out hit, 1f)){
				aCreature.creature.transform.rotation = Quaternion.LookRotation(Vector3.RotateTowards(aCreature.creature.transform.forward, aCreature.creature.transform.right, Random.Range(-5f, 0f), 0f), Vector3.zero);
				aCreature.leftRays.Clear ();
				aCreature.rightRays.Clear ();
				objects.Vision (aCreature);
			}
		}

		// Checks to see what direction the creature is facing so it moves the correct way
		if(aCreature.creature.transform.forward.z > 0 && aCreature.creature.transform.forward.x > 0){
			Debug.Log("++");
			Debug.Log(aCreature.creature.transform.forward.z + " " + aCreature.creature.transform.forward.x);
			aCreature.speed = new Vector3(0.5f, 0f, 0.5f);
		}
		else if(aCreature.creature.transform.forward.z > 0 && aCreature.creature.transform.forward.x < 0){
			Debug.Log("+-");
			Debug.Log(aCreature.creature.transform.forward.z + " " + aCreature.creature.transform.forward.x);
			aCreature.speed = new Vector3(0.5f, 0f, -0.5f);

		}
		else if(aCreature.creature.transform.forward.z < 0 && aCreature.creature.transform.forward.x < 0){
			Debug.Log("--");
			Debug.Log(aCreature.creature.transform.forward.z + " " + aCreature.creature.transform.forward.x);
			aCreature.speed = new Vector3(-0.5f, 0f, -0.5f);

		}
		else if(aCreature.creature.transform.forward.z < 0 && aCreature.creature.transform.forward.x > 0){
			Debug.Log("-+");
			Debug.Log(aCreature.creature.transform.forward.z + " " + aCreature.creature.transform.forward.x);
			aCreature.speed = new Vector3(-0.5f, 0f, 0.5f);

		}
	}

Hope it is one you need.