public void AssignCameraHeight(JSONNode json) { var alpha = json["angle"].AsFloat; var height = CinematographyAttributes.SolveForY(target_go.transform.position, host_go.transform.position, alpha); host_go.transform.position = new Vector3(host_go.transform.position.x, host_go.transform.position.y + height, host_go.transform.position.z); }
public GameObject CreateCamera(TileNode loc, FramingType scale, Orient orient, Hangle hangle, Vangle vangle) { //Debug.Log(scale); GameObject camHost = new GameObject(); //camHost.transform.position = loc.transform.position; var cva = camHost.AddComponent <CinemachineVirtualCamera>(); var cbod = camHost.AddComponent <CinemachineCameraBody>(); var cc = cva.AddCinemachineComponent <CinemachineComposer>(); var cbmcp = cva.AddCinemachineComponent <CinemachineBasicMultiChannelPerlin>(); var camattributes = camHost.AddComponent <CamAttributesStruct>(); camattributes.Set(scale, loc.transform.gameObject.name, orient, hangle, vangle); // composer parameters TODO: tweak via separate gameobject component structure cc.m_HorizontalDamping = 10; cc.m_VerticalDamping = 10; cc.m_LookaheadTime = 0.2f; cc.m_DeadZoneWidth = 0.25f; cc.m_SoftZoneWidth = 0.5f; var framing_data = FramingParameters.FramingTable[scale]; // FStop cbod.IndexOfFStop = CinematographyAttributes.fStops[framing_data.DefaultFStop]; // Lens cbod.IndexOfLens = CinematographyAttributes.lenses[framing_data.DefaultFocalLength]; // set at planning time. //cbod.FocusTransform = target_go.transform; // create small amount of noise cbmcp = cva.AddCinemachineComponent <CinemachineBasicMultiChannelPerlin>(); cbmcp.m_NoiseProfile = CinematographyAttributes.standardNoise; cbmcp.m_AmplitudeGain = 0.5f; cbmcp.m_FrequencyGain = 1f; // worldDirectionOf Camera relative to location transform var camTransformDirection = DegToVector3(camattributes.OrientInt + camattributes.HangleInt); // calculate where to put camera var fakeTarget = CreateFakeTarget(actors[0].gameObject, loc.transform); var camDist = CinematographyAttributes.CalcCameraDistance(fakeTarget, scale); GameObject.DestroyImmediate(fakeTarget); cbod.FocusDistance = camDist; // Calculate Camera Position camHost.transform.position = loc.transform.position + camTransformDirection * camDist; var height = CinematographyAttributes.SolveForY(loc.transform.position, camHost.transform.position, 0.5f, camattributes.VangleInt); camHost.transform.position = new Vector3(camHost.transform.position.x, height, camHost.transform.position.z); // Gives starting orientation of camera. At planning time, a "lookAt" parameter is set to specific target. camHost.transform.rotation.SetLookRotation(loc.transform.position); // Set Name of camera object camHost.name = string.Format("{0}.{1}.{2}.{3}.{4}", loc.name, scale, camattributes.targetOrientation, camattributes.hangle, camattributes.vangle); return(camHost); }