Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Gamershaze · Dec 01, 2014 at 04:06 AM · cameramobilecamera-movementasset store

[Unanswered] "Pixel Perfect" Mobile 'CoC Style' Touch Camera Movement - Complete Script Included.

Edit: I've added an [Unanswered] tag, just to make everything clear. This is mainly due to the question having well over a hundred views, but only one reply and that from when it was first created; almost two weeks ago now. I'll continue to update my progress as it comes in, but I need some help here.


Hey Unity Answers!

Firstly I'd like to apologize for the title, I hate when people essentially ask 'how do i make this popular product'; this is not that. However, I don't know quite how else how to phrase it.

I'm searching for an asset, preferably something to purchase from the Store or remake from a set of tutorials.. To gain a camera movement system similar to Clash of Clans, on the mobile plateform. (iOS to be specific.) Please don't get me wrong, I've done a lot of searching. Hours upon hours of searching, just to begin prototyping this small project. I've purchased one of multiple assets, only to find it's been either broken or not quite scored what it promised. Here's a basic list of definitions for what it should do.

  • Over-head/Topdown View (Similar to Clash of Clans/Related products.)

  • Pan with finger movement.

  • Pinch to Zoom In/Out

  • Modifiable limits on how far it can zoom in/out, and how far it can go in each direction.

  • "Pixel Perfect" in that what you put your fingers down on, never leaves from under your fingers as you move. While most movement scripts just travel in the swiped direction, losing any feedback from where your fingers were actually placed from the game world. Bolded as this was just edited in.

As always, any help is more than greatly appreciated.


Update 12/02/14 Here's an edit I've decided to implement, after purchasing so many assets to no avail. Hopefully it'll help someone else save that money.

Here's a list of assets that do NOT preform the above task, and anyone seeking for a simple camera asset such as above should look elsewhere.

  • FingerGestures (Very buggy, couldn't implement both pan and pinch features at run time, and often misinterpreted simple directional finger movements/spazzed out.)

  • ISRTS Camera (Too unstable.)

  • ControlFreak (Can only modify a specific materials transform values such as scale.)

Seventy bucks wasted so far, to no avail. Still searching for input and suggestions, here.



Update 12/08/14

I've included an incomplete, yet functional script in the Answers section below. This utilizes multiple basic features we sought after, such as pan, and pinch-to-zoom for mobile. However, it still lacks the "Pixel Perfect" aspect which is vital in accuracy and fluid gameplay.

My current concept to pin-point the movement system, involves modifying the speed to finger movement. Currently everything is dynamic to finger movement, apart from speed. Perhaps (velocity * direction = location)?

Could use more input from others, will post any updates or progress I find.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image savlon · Feb 21, 2015 at 07:46 AM 0
Share

Check this tutorial out for Clash of Clans style camera movement https://www.youtube.com/watch?v=PJVy5rOpdDY

7 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Arctodus · Feb 21, 2015 at 12:36 AM

I just had to implement this for my project as well. Since you already have panning working you know how to get the current & previous Vector2 screen space positions so I'll pick up from there.

The gist of it is, from each of those screen space positions you ray cast to the world taking the camera perspective into account. This gives you 2 world space positions. Then you determine the delta of those positions to apply movement to your camera.

 public void ScreenPan( Vector2 curPosition, Vector2 lastPosition )
 {
     // create a ray from the current touch point into the world
     Ray curPosRay  = Camera.main.ScreenPointToRay( curPosition );
 
     // fire that ray out and see if it hits anything 
     RaycastHit curHitInfo;
     if( Physics.Raycast( curPosRay, out curHitInfo ) )
     {
         // we have a hit, do the same for the last position
         Ray lastPosRay = Camera.main.ScreenPointToRay( lastPosition );
         RaycastHit lastHitInfo;
         if( Physics.Raycast( lastPosRay, out lastHitInfo ) )
         {
             // get the delta from those positions
             Vector3 deltaPos = curHitInfo.point - lastHitInfo.point;
 
             // zap y changes, we're only concerned about the x/z plane
             deltaPos.y = 0;
 
             // reverse the direction to negate the movement such that the touch point
             // stays over the same spot once the camera moves.
             deltaPos *= -1;
 
             // apply the pan
             transform.position += deltaPos;
         }
     }
 }
 

Notes: In my code I have other stuff which I've removed here to try and keep this answer directly pertinent to your question (camera bounds checking, only ray casting against certain layers, etc). My apologies if this code contains some minor errors/isn't ready to compile as I have not tested it with that stuff removed. Hopefully it will get you where you want to be with pixel accurate panning.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by BitBenderGames · Sep 03, 2015 at 06:21 PM

Hey there,

I just released on the asset store a camera script (with integrated item picking) that had your listed points in mind when developing. In particular I wanted to reach the quality of the mentioned CoC camera, where there's so many small yet important details, like pixel-perfect scrolling just to mention the most basic one - there's so many more fine things going on in the background to make it feel really natural. Feel free to read more about the asset in the official thread:

Forum Thread

Asset Store Link: http://u3d.as/iQA

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by jamius19 · Nov 14, 2015 at 07:25 PM

Use this asset! just perfect!

AND ITS FREE!!! https://www.assetstore.unity3d.com/en/#!/content/14489

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by M-G-Production · Dec 01, 2014 at 04:18 AM

Hi Gamershaze!

You should check this: http://answers.unity3d.com/questions/183365/c-script-for-unity-camera-detect-difference-betwee.html?sort=oldest

and if you are a lazy boy (like me :D) http://fingergestures.fatalfrog.com/

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gamershaze · Dec 01, 2014 at 10:15 AM 0
Share

Thanks a lot for your answer! After a bit of hesitation, I decided to outright buy the asset you mentioned. As an asset would be much more preferred, so I can start rapid prototyping. Sadly I was met with a handful of errors due to the fact it hasn't been updated in over a year. Once I managed past that and dug my heels in, it lacked the qualities I was looking for. It would only allow the pan module or the zoom module to be on at once, and each modules behavior was rather spastic/jittery and didn't quite match the finger input. Still looking.

avatar image
0

Answer by Gamershaze · Dec 07, 2014 at 04:25 AM

Going to answer my own question here, with an incorrect answer that should help the community.

Below is the code for a simple top-down mobile camera movement system, which includes both pan and pinch-to-zoom features.

What it lacks is the "pixel perfect" accuracy of camera systems for games such as CoC. Meaning what you place your finger on, will not stay beneath your finger and results in a very inaccurate feeling. Nonetheless, this will work for prototyping for most people. (From the other Answers I've viewed, everyone had issues achieving the following and or did not post it afterwards.)

Written in C#.

 using UnityEngine;
 using System.Collections;
 
 public class AdvancedCamera : MonoBehaviour {
     
     public float PanSpeed = 0.025F;
     public float PinchSpeed = 0.05F;
 
     // Use this for initialization, or not. That works too.
     void Start () {
     
     }
 
     // Update is called once per frame, of course.
     void Update () {
         // Check if we have one finger down, and if it's moved.
         // You may modify this first portion to '== 1', to only allow pinching or panning at one time.
         if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
             Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
             // Translate along world cordinates. (Done this way so we can angle the camera freely.)
             transform.position -= new Vector3(touchDeltaPosition.x * PanSpeed, 0, touchDeltaPosition.y * PanSpeed);
         }
 
         // Check if we have two fingers down.
         if ( Input.touchCount == 2 )
         {
             Touch touch1 = Input.GetTouch( 0 );
             Touch touch2 = Input.GetTouch( 1 );
             
             // Find out how the touches have moved relative to eachother.
             Vector2 curDist = touch1.position - touch2.position;
             Vector2 prevDist = (touch1.position - touch1.deltaPosition) - (touch2.position - touch2.deltaPosition);
             
             float touchDelta = curDist.magnitude - prevDist.magnitude;
 
             // Translate along local coordinate space.
             Camera.main.transform.Translate(0, 0, touchDelta * PinchSpeed);   
         }
     }
 }
 



If anyone could help edit this and achieve this sought after pixel-perfect result, please post with any ideas or suggestions! Optimization of the above script is also welcome, but it's fairly simple to where I don't believe that will be necessary.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gamershaze · Dec 08, 2014 at 12:33 PM 0
Share

$$anonymous$$y current concept to pin-point the movement system, involves modifying the speed to finger movement. Currently everything is dynamic to finger movement, apart from speed. Perhaps (speed * direction = location)?

Could use more input from others, will post any updates or progress I find.

  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

33 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Issue with clamping camera 1 Answer

Cinemachine Confiner 2D shift my camera view 0 Answers

Jittery camera when following the player within a prefab 0 Answers

Smooth camera script looking at left hand side of character. 0 Answers

Moving between two cameras 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges