It’s supposed to look like this:
It’s the same size as the bottom screenshot but mine still looks wonky. The map size is also the exact same along with the ground.
What exactly is the problem? I do not understand what you mean with “looking wonky”.
Is it that some lines seem to fade? This is because you look at it at an angle, aliasing is happening. This happens because your screen has a finite resolution and you try to render something that would need more resolution to be displayed properly. Try enabling anti-aliasing to ease that problem.
Also, what is that grid? Are those Gizmos or Line renderers? Should this be visible in a build?
It’s only visible to me, it’s so I can figure out placement of my trees for bounds. I’m unsure where anti-aliasing is. Not only are the lines fading but they’re not in a square like the bottom screenshot, mine looks more like a rectangle.
You are viewing it from an angle not orthogonal to the axis of the square… so the square is foreshortened into a rectangle.
How do I know this? Look at your position gizmo in the top screencap: look how short the red arrow is vs the blue… those should be the same length if you are viewing ortho to those axes.
ALSO, check your pivot/center and global/local buttons in the Scene window in the editor.
Shortcut keys are Z and X to toggle those.
This is what it’s looking like now. The game camera isn’t moving at all and the top camera, well it’s stuck on looking at the trees like that.
I’m not following why this is tagged as 2D. What aspect here is using 2D features? You seem to be asking entirely about 3D rendering and there’s no mention of anything 2D.
Are you using Sprites, Tilemap?
You should look into the basics of how the Unity Editor works. You have your game view and your scene view. Your game view shows your scene from the perspective of an actual Camera component that lives in your scene. This is what players will see when they start the game that you have built.
The other view is your scene view. This is sort of a “virtual camera”, through which you see your scene for editing. You can move around here, rotate, and zoom in using your keyboard and mouse. This scene camera can be set to orthographic, which is the case for you. That way, everything has the same scale and you loose all perspective. This can be helpful at times, but it sounds like this is something you do not want. In the last screenshot you posted you have also enabled “2D”, which is basically an orthographic view from a single axis.
It wasn’t meant to be tagged with 3D. Sorry about that.
Thank you, I was able to get it to be correct. And it is supposed to be an orthographic view. However, my game just will not move. It moves around in scene perfectly but I can’t click on “shop” nor move around the map, it’s just zoomed into that tree when I’m in game.
The camera in your game needs to be moved via your own logic.
I have no idea what “shop” means. We don’t know your project or what you are trying to achieve, so it is very hard to help you.
Sorry, I should’ve said more. “Shop” is a clickable button, when clicked, it opens an image. As for when going in game, I can’t do anything. Can’t move, can’t click, can’t zoom in or out. The code is set up for it.
Here is the camera controller code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.CompilerServices;
using Unity.VisualScripting;
using UnityEngine;
using UnityEditor.Experimental.GraphView;
using Unity.VisualScripting.Dependencies.Sqlite;
public class CameraController : MonoBehaviour
{
[SerializeField] private Camera _camera = null;
[SerializeField] private float _moveSpeed = 50;
[SerializeField] private float _moveSmooth = 5;
[SerializeField] private float _zoomSpeed = 5f;
[SerializeField] private float _zoomSmooth = 5;
private Controls _inputs = null;
private bool _zooming = false;
private bool _moving = false;
private Vector3 _center = Vector3.zero;
private float _right = 10;
private float _left = 10;
private float _up = 10;
private float _down = 10;
private float _angle = 45;
private float _zoom = 5;
private float _zoomMax = 10;
private float _zoomMin = 1;
private Vector2 _zoomPositionOnScreen = Vector2.zero;
private Vector3 _zoomPositionInWorld = Vector3.zero;
private float _zoomBaseValue = 0;
private float _zoomBaseDistance = 0;
private Transform _root = null;
private Transform _pivot = null;
private Transform _target = null;
private void Awake()
{
_inputs = new Controls();
_root = new GameObject("CameraHelper").transform;
_pivot = new GameObject("CameraPivot").transform;
_target = new GameObject("CameraTarget").transform;
_camera.orthographic = true;
_camera.nearClipPlane = 0;
}
private void Start()
{
Initialize(Vector3.zero, 40, 40, 40, 40, 45, 10, 5, 20);
}
public void Initialize(Vector3 center, float right, float left, float up, float down, float angle, float zoom, float zoomMin, float zoomMax)
{
_center = center;
_right = right;
_left = left;
_up = up;
_down = down;
_angle = angle;
_zoom = zoom;
_zoomMin = zoomMin;
_zoomMax = zoomMax;
_camera.orthographicSize = _zoom;
_zooming = false;
_moving = false;
_pivot.SetParent(_root);
_target.SetParent(_pivot);
_root.position = center;
_root.localEulerAngles = Vector3.zero;
_pivot.localPosition = Vector3.zero;
_pivot.localEulerAngles = new Vector3(_angle, 0, 0);
_target.localPosition = new Vector3(0, 0, -100);
_target.localEulerAngles = Vector3.zero;
}
private void OnEnable()
{
_inputs.Enable();
_inputs.Main.Move.started += _ => MoveStarted();
_inputs.Main.Move.canceled += _ => MoveCanceled();
_inputs.Main.TouchZoom.started += _ => ZoomStarted();
_inputs.Main.TouchZoom.canceled += _ => ZoomCanceled();
}
private void OnDisable()
{
_inputs.Main.Move.started -= _ => MoveStarted();
_inputs.Main.Move.canceled -= _ => MoveCanceled();
_inputs.Main.TouchZoom.started -= _ => ZoomStarted();
_inputs.Main.TouchZoom.canceled -= _ => ZoomCanceled();
_inputs.Disable();
}
private void MoveStarted()
{
if (UI_Main.instance.isActive)
{
_moving = true;
}
}
private void MoveCanceled()
{
_moving = false;
}
private void ZoomStarted()
{
if (UI_Main.instance.isActive)
{
Vector2 touch0 = _inputs.Main.TouchPosition0.ReadValue<Vector2>();
Vector2 touch1 = _inputs.Main.TouchPosition1.ReadValue<Vector2>();
_zoomPositionOnScreen = Vector2.Lerp(touch0, touch1, 0.5f);
_zoomPositionInWorld = CameraScreenPositionToPlanePosition(_zoomPositionOnScreen);
_zoomBaseValue = _zoom;
touch0.x /= Screen.width;
touch1.x /= Screen.width;
touch0.y /= Screen.height;
touch1.y /= Screen.height;
_zoomBaseDistance = Vector2.Distance(touch0, touch1);
_zooming = true;
}
}
private void ZoomCanceled()
{
_zooming = false;
}
private void Update()
{
if (Input.touchSupported == false)
{
float mouseScroll = _inputs.Main.MouseScroll.ReadValue<float>();
if (mouseScroll > 0)
{
_zoom -= 3f * Time.deltaTime;
}
else if (mouseScroll < 0)
{
_zoom += 3f * Time.deltaTime;
}
}
if (_zooming)
{
Vector2 touch0 = _inputs.Main.TouchPosition0.ReadValue<Vector2>();
Vector2 touch1 = _inputs.Main.TouchPosition1.ReadValue<Vector2>();
touch0.x /= Screen.width;
touch1.x /= Screen.width;
touch0.y /= Screen.height;
touch1.y /= Screen.height;
float currentDistance = Vector2.Distance(touch0, touch1);
float deltaDistance = currentDistance - _zoomBaseDistance;
_zoom = _zoomBaseValue - (deltaDistance * _zoomSpeed);
Vector3 zoomCenter = CameraScreenPositionToPlanePosition(_zoomPositionOnScreen);
_root.position += (_zoomPositionInWorld - zoomCenter);
}
else if (_moving)
{
Vector2 move = _inputs.Main.MoveDelta.ReadValue<Vector2>();
if (move != Vector2.zero)
{
move.x /= Screen.width;
move.y /= Screen.height;
_root.position -= _root.right.normalized * move.x * _moveSpeed;
_root.position -= _root.forward.normalized * move.y * _moveSpeed;
}
}
AdjustBounds();
if (_camera.orthographicSize != _zoom)
{
_camera.orthographicSize = Mathf.Lerp(_camera.orthographicSize, _zoom, _zoomSmooth * Time.deltaTime);
}
if (_camera.transform.position != _target.position)
{
_camera.transform.position = Vector3.Lerp (_camera.transform.position, _target.position, _moveSmooth * Time.deltaTime);
}
if (_camera.transform.rotation != _target.rotation)
{
_camera.transform.rotation = _target.rotation;
}
}
private Vector3 CameraScreenPositionToWorldPosition(Vector2 position)
{
float h = _camera.orthographicSize * 2f;
float w = _camera.aspect * h;
Vector3 anchor = _camera.transform.position - (_camera.transform.right.normalized * w / 2f) - (_camera.transform.up.normalized * h / 2f);
return anchor + (_camera.transform.right.normalized * position.x / Screen.width * w) + (_camera.transform.up.normalized * position.y / Screen.height * h);
}
private void AdjustBounds()
{
if (_zoom < _zoomMin)
{
_zoom = _zoomMin;
}
if(_zoom > _zoomMax)
{
_zoom = _zoomMax;
}
float h = PlaneOrthographicSize();
float w = h * _camera.aspect;
if(h > (_up + _down) / 2f)
{
float n = (_up + _down) / 2f;
_zoom = n * Mathf.Sin(_angle * Mathf.Deg2Rad);
}
if (w > (_right + _left) / 2f)
{
float n = (_right + _left) / 2f;
_zoom = n * Mathf.Sin(_angle * Mathf.Deg2Rad) / _camera.aspect;
}
h = PlaneOrthographicSize();
w = h * _camera.aspect;
Vector3 tr = _root.position + _root.right.normalized * w + _root.forward.normalized * h;
Vector3 tl = _root.position - _root.right.normalized * w + _root.forward.normalized * h;
Vector3 dr = _root.position + _root.right.normalized * w - _root.forward.normalized * h;
Vector3 dl = _root.position - _root.right.normalized * w - _root.forward.normalized * h;
if(tr.x > _center.x + _right)
{
_root.position += Vector3.left * Mathf.Abs (tr.x - (_center.x + _right));
}
if (tl.x < _center.x + _left)
{
_root.position += Vector3.right * Mathf.Abs((_center.x - _left) - tl.x);
}
if (tr.z > _center.z + _up)
{
_root.position += Vector3.back * Mathf.Abs(tr.z - (_center.z + _up));
}
if (dl.z < _center.z + _down)
{
_root.position += Vector3.forward * Mathf.Abs((_center.z - _down) - dl.z);
}
}
private float PlaneOrthographicSize()
{
float h = _zoom * 2f;
return h / Mathf.Sin(_angle * Mathf.Deg2Rad);
}
private Vector3 CameraScreenPositionToPlanePosition(Vector2 position)
{
Vector3 point = CameraScreenPositionToWorldPosition(position);
float h = point.y - _root.position.y;
float x = h / Mathf.Sin(_angle * Mathf.Deg2Rad);
return point + _camera.transform.forward.normalized * x;
}
}
That sounds like you wrote a bug… and that can only mean… time to start debugging!
By debugging you can find out exactly what your program is doing so you can fix it.
Use the above techniques to get the information you need in order to reason about what the problem is.
You can also use Debug.Log(...);
statements to find out if any of your code is even running. Don’t assume it is.
Once you understand what the problem is, you may begin to reason about a solution to the problem.