changing camera angle problem -

I’ve used a combination of a static camera and the SmoothFollow camera to achieve a top down → 3rd person effect. I’m still getting used to the Lerp function, but using what was already there as mentor code I got the effect I wanted perfectly…except for one problem.

When I press a certain joystick key, it turns on a variable called moveCam and when moveCam is true, it utilizes the SmoothFollow script. When its false it utilizes the static camera script.

But I can never truly turn it to false. I’ve tested it by setting a button to change it to false, and then it works fine. The problem I’m having is I can’t quite figure out how to turn it off.

Essentially, here is the code:

		if (!target)
			return;
	
		wantedRotationAngle = transform.eulerAngles.y;
		wantedHeight = target.position.y + changeHeight;
		
		currentRotationAngle = transform.eulerAngles.y;
		currentHeight = transform.position.y;
		currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);


		currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime;
		currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
		
		currentPosition = transform.position;
		wantedPosition = target.position-currentRotation*Vector3.forward*changeDistance;
		transform.position  = Vector3.Lerp(currentPosition,wantedPosition,positionDamping*Time.deltaTime);
		
///////// HERE IS THE PART THAT IS GIVING ME THE TROUBLE
          if (transform.position.y=wantedPosition.y)
			{
			moveCam = false;	
			}

/////// IVE TRIED MANY THINGS BUT CAN'T QUITE GET IT TO WORK
/////// I UNDERSTAND THAT THESE ARE FLOATS AND PROBABLY NEVER ACTUALLY EQUAL EACH OTHER
///////  BUT I CAN'T THINK OF ANOTHER WAY TO DO THIS.

		transform.position.y = currentHeight;
		transform.LookAt (target);
			
			
		}
///////// HERE IS THE PART THAT IS GIVING ME THE TROUBLE
          if (transform.position.y=wantedPosition.y)
			{
			moveCam = false;	
			}

That is an assignment, not a boolean condition. Don’t you want to use == there instead?

I don’t see in your code where you’re drawing wantedPosition from, but if you want to test two floats for ‘loose’ equality then try using Mathf.Approximately().