public void Execute() { Entity cameraEntity = entityDatabase.QueryEntity <CameraComponent>(); Entity playerEntity = entityDatabase.QueryEntity <PlayerComponent>(); CameraTargetComponent cameraTargetComponent = cameraEntity.AddComponent <CameraTargetComponent>(); cameraTargetComponent.Add(CameraTargetKey.Target, playerEntity); cameraTargetComponent.offset = cameraTargetComponent.entity.GetComponent <TransformComponent>().transform.position - playerEntity.GetComponent <TransformComponent>().transform.position; }
public void Update() { Entity cameraEntity = entityDatabase.QueryEntity <CameraComponent>(); CameraTargetComponent cameraTargetComponent = cameraEntity.GetComponent <CameraTargetComponent>(); ICameraData cameraData = entityDatabase.QueryType <GameDataComponent>().gameData.cameraData; Entity targetEntity = cameraTargetComponent[CameraTargetKey.Target]; Vector3 targetCamPos = targetEntity.GetComponent <TransformComponent>().transform.position + cameraTargetComponent.offset; Transform cameraTranform = cameraEntity.GetComponent <TransformComponent>().transform; cameraTranform.position = Vector3.Lerp(cameraTranform.position, targetCamPos, cameraData.smoothing * Time.deltaTime); }