Camera zooms farther out when accelerating, in when decelerating, returns to normal when not accelerating?

I’m making a flight simulator and everything is working out fine, but the camera chase is really bugging me. I the camera coded to move away from the plane when I was at a higher speed and move in at a lower speed. The problem is, when the plane goes too fast, the camera moves so far away that the plane is practically unseeable. I considered having a limit for how far the camera could be away from the plane, but then when the plane accelerated beyond a speed that would be in the limit, it wouldn’t really show in the camera chase.

Here is the code that I am using:

Vector3 moveCamTo = transform.position - transform.forward *10.0f + Vector3.up * 5.0f;
		float bias = 0.96f;
		Camera.main.transform.position = Camera.main.transform.position * bias +
										 moveCamTo * (1.0f-bias);
		Camera.main.transform.LookAt (transform.position + transform.forward * 30.0f);

I want to have the camera move in only when the plane is accelerating and move out only when it is deaccelerating, and when it is at a constant speed, it will return to the original position (move in if it is far out, move away if it is too far in) but I have no idea how to code this.

I’d greatly appreciate any help.

Thanks!

-wwsamson

I’d split it into two scripts. One script will constantly figure out where it wants the camera to be and the other will actually move the camera.
Apply your limits to the first script. In the script that moves the camera you can constantly LERP towards where the first script wants you to be but never actually get there. This way if you’re accelerating the camera will still move the whole time but also adhere to the limit. Then you can perform some logic to figure out when you’re at a constant enough speed and lock the camera position.

It’s going to be complicated in any case. Consider using an FSM