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
0
Question by infinitypbr · Feb 05, 2013 at 10:29 PM · swipe

How can I make this "swipe w/ force"? Camera tilt/pan on swipe.

The code below works fine -- when player moves finger in the top 80% of the screen, the camera goes up/down and all that.

however, as soon as they let go, it stops. I'd like them to be able to do a swipe that slowly stops, rather than right away. Any ideas on how to achieve that?

Thanks!

 for (var i = 0; i < Input.touchCount; ++i) 
     {
         if (Input.GetTouch(i).position.y > (screenHeight / 10) * 2)  // if the touch is in the top 80% of the screen (the play field, basically)
         {
             if (Input.GetTouch(i).phase == TouchPhase.Moved)
             {
                 // Finger moved, so it's a swipe
                 var touchDeltaPosition:Vector2 = Input.GetTouch(i).deltaPosition;
                 playerObject.transform.eulerAngles.x += (-touchDeltaPosition.y * rotateSpeed);
                 playerObject.transform.eulerAngles.y -= (-touchDeltaPosition.x * rotateSpeed);
             }
         }
     }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Kirlim · Feb 06, 2013 at 01:05 AM

There are various ways to achieve what I believe you want. Usually, these types of problems are better solved if you try to use helping variables. For example, two possibilities I can hint you:

  • Store the last position of the touch that moves the camera. Then, you gradually move that cameras with a function that depends on the distance. If you're not really into maths, try moving, for example, (distance from camera to position) percentagge Time.deltaTime every frame. If you're into maths, you can try using the Vector3.Lerp with the positions. Lerp uses a parameter ranging from 0 to 1 to decide the resulting value, so you can use any trick as (elapsed time / total animation time) ^ x (x from 1 to any number), or achieving really smooth effects by using Mathf.Sin((elapsed time / total time) * Mathf.PI). Actually, any continuous function where f(0) = 0 and f(1) = 1 with f'(0) = f'(1) = 0 will have a good smooth effect. Talk about calculus =D. Total time is the time you want the effect to take to execute, and elapsed time is the time its been executing. I suggest using times with lerp because you can tune how long the effect will take.

  • Use the swype to calculate an acceleration, and then move the camera by using that acceleration. You can make a big deceleration if the touch ends.

I guess I did a pretty confuse attempt of an answer...

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

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

10 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

Related Questions

Swipe Gesture iOS 1 Answer

Controlling Animation ON TOUCH 0 Answers

Mouse Swipe? 1 Answer

Android how to use swipe to make certain part of an object fade out? 0 Answers

swipe camera movement wont stay between limitations 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