Skip to content

Camera movement in Unity script, specific built for mobile devices

License

Notifications You must be signed in to change notification settings

sergane13/Camera-Movement-By-Touch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HitCount Watchers


🎥 Camera Movement By Touch 👆

README for Camera Movement
Explore the docs »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Project structure
  5. Colaborators
  6. License

About The Project


Logo


Description

Out of the box sollution for managing movement of camera in your game and interaction with different gameObjects using the collider.

Features

  • 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]


Built With

Working with

Getting Started

Installation

  1. Clone the repo

    git clone https://github.com/sergane13/Camera-Movement-By-Touch
  2. Open project in Unity

    Tested Unity version: 2021.2.0f1
  3. Add scripts to any gameObject you want and assign the main camera to it

    Logo

How to use 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

Disclaimer

  • 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.

Usage

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 structure

< 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
   |                          
  ************************************************************************

Colaborators

License

Shield: CC BY-SA 4.0

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

CC BY-SA 4.0

Project Template adapted from Othneil Drew / Best-README-Template.

About

Camera movement in Unity script, specific built for mobile devices

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages