Skip to content

Commit

Permalink
Camera bounds and more MainScene
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMejmun committed Jan 22, 2017
1 parent eb5a594 commit a8d721d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
Binary file modified GGJ17/Assets/Material/SpawnParticleTrailMaterial.mat
Binary file not shown.
Binary file modified GGJ17/Assets/Material/SpawnSplashParticleTrailMaterial.mat
Binary file not shown.
Binary file modified GGJ17/Assets/Prefab/BuildingBlocks/Building_Extractor.prefab
Binary file not shown.
Binary file modified GGJ17/Assets/Scene/MainScene.unity
Binary file not shown.
37 changes: 28 additions & 9 deletions GGJ17/Assets/Script/IsoCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@
using System.Collections.Generic;
using UnityEngine;

public class IsoCamera : MonoBehaviour {

public class IsoCamera : MonoBehaviour
{

public float panSpeed = 10, rotateSpeed = 100, zoomSpeed = 5;
private const float camFocusHeight = 0;
private Vector3 focusPoint, mousePosition;
private new Camera camera;
public float zoomMin, zoomMax;

// Use this for initialization
void Awake () {
// Use this for initialization
void Awake()
{
camera = GetComponent<Camera>();
Vector3 globalCamForwardDir = transform.forward;
Vector3 downProjectedCamForward = Vector3.Project(transform.TransformVector(Vector3.forward), Vector3.down);
float m = (transform.position.y - camFocusHeight) / downProjectedCamForward.magnitude;
focusPoint = transform.position + globalCamForwardDir * m;
}

// Update is called once per frame
void Update () {

// Update is called once per frame
void Update()
{
#region pan
Vector3 localMove = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
Vector3 groundMove = Vector3.ProjectOnPlane(transform.TransformVector(localMove), Vector3.up);
Expand All @@ -29,8 +33,8 @@ void Update () {
focusPoint += translation;
#endregion
// poll the mouse
if (Input.GetMouseButton(1))
#region rotate
if (Input.GetMouseButton(1))
{
Vector2 rotation = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
rotation *= rotateSpeed * Time.deltaTime;
Expand All @@ -42,7 +46,22 @@ void Update () {
}
#endregion
#region zoom
camera.orthographicSize += Input.mouseScrollDelta.y * zoomSpeed * Time.deltaTime;
// reset if out of bounds
if (camera.orthographicSize < zoomMin)
{
camera.orthographicSize = zoomMin;
}
else if (camera.orthographicSize > zoomMax)
{
camera.orthographicSize = zoomMax;
}
// only move if target position is within bounds
float targetZoom = camera.orthographicSize + Input.mouseScrollDelta.y * zoomSpeed * Time.deltaTime;
if ((targetZoom >= zoomMin) &&
(targetZoom <= zoomMax))
{
camera.orthographicSize = targetZoom;
}
#endregion
}

Expand Down
9 changes: 0 additions & 9 deletions GGJ17/Assets/Script/WorldControl.meta

This file was deleted.

0 comments on commit a8d721d

Please sign in to comment.