Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by BANNERTM · Apr 15, 2012 at 06:02 PM · cameratouchangry

Camera touch control script

I need camera controll by touchscreen like in angry bird and many other 2d games(it look like scrolling).

Comment
Add comment · Show 9
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 BigBlob · Apr 15, 2012 at 06:23 PM 0
Share

Is it like moving the player? - Touch here to move!!!

avatar image BANNERTM · Apr 15, 2012 at 06:39 PM 0
Share

It's like scroll bar - Did you play angry birds? Whan you want to see al level you scroll to left and camera moves to right. I hope somebody understand my poor English

avatar image gregzo · Apr 15, 2012 at 07:22 PM 0
Share

A polite question will give you more answers, I can assure you. Your knowledge of english surely includes "Hello" and "please".

avatar image IgnoranceIsBliss · Apr 15, 2012 at 10:24 PM 0
Share

It's pretty easy - if you can't write this, you'll have trouble with the rest of your game.

Just read in each of the 'Touch' objects in Input.touches and you will be able to then move your camera to suit.

Each touch has a 'phase' - Begun, $$anonymous$$oved, Ended or Cancelled etc.

When you see a touch begin, record where it happened. Then when you see '$$anonymous$$oved' you adjust the camera position based on the difference between the CURRENT position and the position of the initial touch.

avatar image IgnoranceIsBliss · Apr 15, 2012 at 11:34 PM 1
Share

I understand, but if we are going to discuss tone we should probably also view the tone used in the original question.

The poster didn't ask for help - they asked for a complete script to do to he job. It may be why they have no answers.

As it is, I pointed the user towards the technique. The moment they come back with more questions (ideally after reading some of the documentation on dealing with touch events and starting a behaviour in their language of choice) I'm more than happy to help with actual code.

The purpose of this forum is to HELP, not to provide free code on demand.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
4

Answer by IgnoranceIsBliss · Apr 15, 2012 at 11:46 PM

A rough guide to moving the camera based on touch.

This is in C# and moves the camera on the Y axis only. It's pretty rough and hasn't been tested.

If you wanted to fiddle, you could add momentum (so the camera continues to move after your finger raises) and a scaling factor to the deltaPosition so you can turn sensitivity up or down.

 class TouchCameraMover
 {
    // The ID of the touch that began the scroll.
    int ScrollTouchID = -1;
    // The position of that initial touch
    Vector2 ScrollTouchOrigin;
 
    void Update()
    {
        foreach(Touch T in Input.touches)
        {
           //Note down the touch ID and position when the touch begins...
           if (T.phase == TouchPhase.Began)
           {                                    
         if (ScrollTouch == -1)
         {
            ScrollTouchID = T.fingerId;    
            ScrollTouchOrigin = T.position;    
             }
           }
           //Forget it when the touch ends
           if ((T.phase == TouchPhase.Ended) || (T.phase == TouchPhase.Canceled))
           {                                    
               ScrollTouchID = -1;    
           }
           if (T.phase == TouchPhase.Moved)
           {
                 //If the finger has moved and it's the finger that started the touch, move the camera along the Y axis.
             if (T.fingerId == ScrollTouchID)
             {
                      Vector3 CameraPos = Camera.main.transform;
                      Camera.main.transform = new Vector3(CameraPos.x,CameraPos.y + T.deltaPosition.y,CameraPos.z);
                 }
           }
        }
    }
 }
Comment
Add comment · Show 3 · 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 anilgautam · Dec 19, 2012 at 10:09 AM 0
Share

1st of all thanks for such a nice script it works perfectly for my case but I want to add momentum in movement how can i do that .

avatar image IgnoranceIsBliss · Dec 20, 2012 at 02:55 AM 0
Share

All you'd need to do is store the speed that the user was scrolling when they released the button (ie the number of pixels per second, using Time.deltaTime).

So for example, you calculate speed with...

 Speed = T.deltaPosition / Time.deltaTime;

Then after they stop touching the screen, keep moving at that speed. Every frame, drop the speed by a certain amount. If you were dropping the speed by 5 pixels per second, you could do so with...

 Speed = Speed - (5 * Time.deltaTime);
avatar image indiasaqib · Oct 21, 2021 at 03:00 AM 0
Share

if we have more people like you, this world would be a better place. thanks alot for your help

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

13 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

Related Questions

Touch not working if camera is moved 0 Answers

perspective camera into android 0 Answers

Rotate Camera around Object 2 Answers

i want to help touch functionalities for android how will i do that ?? 0 Answers

Rotate Camera around object with touch 0 Answers


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