Commit 50404896 authored by 18손재민's avatar 18손재민 Committed by 15박보승

카메라 회전 및 이동 방식 수정, 현재 이동과 회전이 동시에 됨 나중에 수정할 것

parent c60bf36c
......@@ -5,6 +5,7 @@ using UnityEngine;
public class CameraController : MonoBehaviour
{
Vector3 dragOrigin;
Vector3 moveOrigin;
public float dragSpeed;
Vector3 previousPos;
Vector3 previousAngle;
......@@ -14,16 +15,35 @@ public class CameraController : MonoBehaviour
float rotationY = 0;
float sensitivity = 30;
[SerializeField]
Vector3 centerPos = new Vector3(0, 0, 0);
Vector3 distance = new Vector3(0, 0, 0);
/// <summary>
/// Move camera.
/// </summary>
void CameraMove()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
transform.position += new Vector3(verticalInput + horizontalInput, 0, verticalInput - horizontalInput);
if (Input.GetMouseButtonDown(2))
{
moveOrigin = Input.mousePosition;
return;
}
if (!Input.GetMouseButton(2))
{
Vector3 tempVec = centerPos;
centerPos = new Vector3(Mathf.Clamp(Mathf.Round(centerPos.x * 2) / 2, MapManager.inst.currentMap.minBorder.x, MapManager.inst.currentMap.maxBorder.x),
0, Mathf.Clamp(Mathf.Round(centerPos.z * 2) / 2, MapManager.inst.currentMap.minBorder.y, MapManager.inst.currentMap.maxBorder.y));
transform.Translate(centerPos - tempVec, Space.World);
return;
}
float previousY = transform.position.y;
Vector3 centerDiff = transform.position;
Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - moveOrigin);
moveOrigin = Input.mousePosition;
transform.Translate(new Vector3(pos.x * -8, pos.y * -8, 0), Space.Self);
transform.position = new Vector3(transform.position.x, previousY, transform.position.z);
centerPos += transform.position - centerDiff;
centerPos.y = 0;
}
/// <summary>
......@@ -127,6 +147,7 @@ public class CameraController : MonoBehaviour
{
Camera.main.fieldOfView = mapFov;
transform.eulerAngles = new Vector3(30, transform.eulerAngles.y, transform.eulerAngles.z);
distance = transform.position - centerPos;
}
// Update is called once per frame
......@@ -136,7 +157,19 @@ public class CameraController : MonoBehaviour
{
if (!PlayerController.inst.isPlayerShooting)
{
//CameraMove();
CameraMove();
CameraDrag();
}
else
......
......@@ -7,6 +7,7 @@ public class Map : MonoBehaviour
{
[Header("Map Data")]
public int maxMapSize;
public Vector2Int maxBorder, minBorder;
public Dictionary<Vector2Int, Floor> floorGrid;
public Dictionary<Vector2, Wall> wallGrid;
public Dictionary<Vector2Int, IObject> objectGrid;
......@@ -65,6 +66,10 @@ public class Map : MonoBehaviour
floorGrid.Add(pos, Instantiate(MapManager.inst.floor, new Vector3(pos.x, 0, pos.y), Quaternion.identity, floors.transform).GetComponent<Floor>());
floorGrid[pos].mapPos = pos;
floorGrid[pos].isGoalFloor = isGoal;
if (pos.x > maxBorder.x) maxBorder.x = pos.x;
else if (pos.x < minBorder.x) minBorder.x = pos.x;
if (pos.y > maxBorder.y) maxBorder.y = pos.y;
else if (pos.y < minBorder.y) minBorder.y = pos.y;
if (GameManager.aFloor >= 0 && isGoal)
clearConditions[GameManager.aFloor].IsDone(0, 1);
StartCoroutine(MapManager.inst.Rebaker());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment