// Update is called once per frame void Update() { headerText.text = "Camera: " + cam.name; positionText.text = "Position: " + cam.transform.position.ToString(); stateText.text = "State: " + stateController.GetCameraState().ToString() + ", " + stateController.GetOrientationState(); orbitText.text = "Orbit input: " + camInput.GetOrbitInput().ToString(); }
/// <summary> /// Main camera update function, and the only one which moves the camera. Called in either Update, LateUpdate, or FixedUpdate, depending on setting. /// </summary> /// <param name="deltaTime">Time since the last camera update, in seconds.</param> private void UpdateCamera(float deltaTime) { /* Update relevant info */ UpdateConvenienceComponentVars(); UpdateTrackers(deltaTime); /* Move camera */ Vector3 initialClipPanePos = cam.GetNearClipPaneCentreWorld(); //cache camera's near clip pane centre before any movement for collision avoidance cam.transform.position = GetCameraMoveResult(stateController.GetCameraState(), deltaTime); if (camParams.useCamWhiskers) { cam.transform.position = GetCamWhiskerResult(cam.transform.position, GetCamWhiskerOffset(), deltaTime); } if (camParams.avoidFollowTargetOcclusion) { cam.transform.position = GetOcclusionPullInResult(deltaTime); } cam.transform.rotation = LookAtTarget(deltaTime); if (camParams.useMinDistance) { cam.transform.position = ClampCameraMinDistance(camParams.minDistanceFromTarget); } //max distance clamp is dependant on whether the camera collided with geometry this tick Vector3 collisionAvoidPos = Vector3.zero; float maxDist = camParams.maxDistanceFromTarget; if (camParams.avoidCollisionWithGeometry) { collisionAvoidPos = AvoidCollisions(initialClipPanePos, cam); } if (collisionAvoidPos != cam.transform.position) { cam.transform.position = collisionAvoidPos; } if (camParams.useMaxDistance) { cam.transform.position = ClampCameraMaxDistance(maxDist); } //TEST Vector3 occlusionAvoidPos = GetOcclusionPullForwardPosition(cam, followTarget.transform.position, 1f); Debug.DrawLine(cam.transform.position, occlusionAvoidPos, Color.yellow); Debug.DrawRay(occlusionAvoidPos, Vector3.up * cam.nearClipPlane, Color.yellow); Debug.DrawRay(occlusionAvoidPos, Vector3.right * cam.nearClipPlane, Color.yellow); Debug.DrawRay(occlusionAvoidPos, Vector3.down * cam.nearClipPlane, Color.yellow); Debug.DrawRay(occlusionAvoidPos, Vector3.left * cam.nearClipPlane, Color.yellow); Debug.DrawRay(occlusionAvoidPos, Vector3.forward * cam.nearClipPlane, Color.yellow); Debug.DrawRay(occlusionAvoidPos, Vector3.back * cam.nearClipPlane, Color.yellow); #if TPC_CAMERA_MOVEMENT_DEBUG debugInfo.followTargetPos = followTarget.transform.position; debugInfo.camNearClipPanePos = cam.GetNearClipPaneCentreWorld(); debugInfo.camVirtualSize = virtualCameraSphereRadius; #endif }
private void Update() { UpdateCurrentOrbitAngles(); UpdateOrbitHoldAngles(stateController.GetCameraState()); }