README for Camera Movement
Explore the docs »
Table of Contents
Out of the box sollution for managing movement of camera in your game and interaction with different gameObjects using the collider.
-
Panning with one finger in any direction with the finger remaining always under the touched object [also know as pixel perfect panning]
-
Panning has inertia
-
WorldSpace limits and orthographic limits
-
Gizmo drawing in UNITY EDITOR to know the limits of the camera
-
Visual feedback for achieving minimum ortho
-
Pinching with two or more fingers with zooming target in the middle point of the two fingers
-
Supports panning during the pinching operation
-
Ignores any UI elements during touch operation
-
Detects tap on GameObjects for opening screens or panels [UI canvas]
- Unity in
-
Clone the repo
git clone https://github.com/sergane13/Camera-Movement-By-Touch
-
Open project in Unity
Tested Unity version: 2021.2.0f1
-
Add scripts to any gameObject you want and assign the main camera to it
- The first script is
PanPinchCameracMovement.cs
that is used for managing the inputs from the user [touch inputs].cameraToMove
- The camera component that will be manipulated by the user
limitXmin
- The minimum position of the camera field of view on X axis
limitXmax
- The maximum position of the camera field of view on X axis
limitYmin
- The minimum position of the camera field of view on Y axis
limitYmax
- The maximum position of the camera field of view on Y axis
orthoMin
- The minum orhographic size of the camera
orthoMax
- The maximum orhographic size of the camera
interpolationStep
- Sensitivity value for calculating the camera drag (inertia) after release of the finger. Reccomended value: 0.2
- The second script is
TapOnGameObject.cs
that is responsible vor validating the "tap" on a gameobject veryfiyng that the finger has not left the initial touch position, taking in consideration a small sensitivity to get rid of false positives.sensitivity
- value for filtering touch.deltaposition to consider the touch as MOVING
- Reccomended value: 0.2
- Both scripts are using the old input system
⚠️ - Using the new input system will results in a lot of errors and incompatibilities, especialy with managing touch on UI elements
- Using Device Simulator will create unwanted behaviour due to unknown reasons. Test the scripts by building an apk file and intalling it on your device.
After reasearching for quite a while, we could not find a good and sustainable sollution for camera movement for mobile aplications. In our case it was needed to build a 2d city builder game where user has to interact with the environment. It can be easily used in any 2d isometric games similar with HayDay
or Clash of Clans
. We tried to mimic the bahaviour that it is found in supercell games for camera movement, but adaptated for our usage.
- You can test the usage of the scripts in our game Khyron Realm
- You can also see the Youtube video
< PROJECT ROOT >
|
|--Editor
|--Resources
|-- first.png
|-- second.png
|--Scenes
|--Test-Scenes.unity
|--Scripts
|--PanPinchCameraMovement.cs # Script for managing movement of camera
|--TapOnGameObject.cs # Script for managing touch of a gameObject
|
************************************************************************
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Project Template adapted from Othneil Drew / Best-README-Template.