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