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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Pauls · Dec 20, 2013 at 05:32 PM · touchdrag

Object sometimes stops after drag, instead of sliding?

Hi,

I would like to make the camera slide a little bit more when the touch ends. With this code, the effect works, but sometimes it stops right after the second attempt. The camera is supposed to slide every time the touch has moved and ends, but it sometimes stops for an unknown reason. Would someone have any idea why?

 if (Input.touchCount > 0 ){
     if ( Input.GetTouch(0).phase == TouchPhase.Began ) {
         //_doLongMove = false;
     }
     if ( Input.GetTouch(0).phase == TouchPhase.Moved ) {
         // Get movement of the finger since last frame
         touchDeltaPosition = Input.GetTouch(0).deltaPosition;
         float speedDrag = 0.2f;
         transform.Translate (-touchDeltaPosition.x * speedDrag, 0, -touchDeltaPosition.y * speedDrag);
     }
     if ( Input.GetTouch(0).phase == TouchPhase.Ended ) {
         speed = 0.3f;
         _doLongMove = true;
     }
 }
 if ( _doLongMove ) {
     doLongMove();
 }
         
         
 void doLongMove(){
     float slowDown = 0.01f;
     float force = 1.5f;
     if ( speed > 0 ){
         speed -= slowDown;
     }
     if ( speed < 0 ) {
         speed = 0;
         _doLongMove = false;
     }
     transform.Translate (-touchDeltaPosition.x * force * speed, 0, -touchDeltaPosition.y * force * speed);
 }

EDIT:

I also tried this, but it stops as well, sometimes 3 times in a row, then it works fine :

 if ( wasDragging && Input.touchCount == 0 ){
             speed=0.3f;
             _doLongMove = true;
             wasDragging = false;
         }
         if ( _doLongMove ) {
             doLongMove();
         }

Thanks

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
0

Answer by Kinos141 · Dec 20, 2013 at 06:11 PM

You should try a Mathf.Lerp that takes the current speed and lerps it to zero over time. That way you can have it slow to a halt.
I would also use iTween.

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 Pauls · Dec 20, 2013 at 06:35 PM 0
Share

Thanks, I don't know if what I said was clear to describe the problem : when I make several attempts in the same direction to move the camera, ins$$anonymous$$d of sliding continuously, it stops, as if I stopped the finger on the screen, but I did not. Every time I lift the finger, I would like the object to keep on moving. The slow down works fine though (with a $$anonymous$$athf.Lerp as well), except when the camera stops: for some reason, the 3d or 4th time, it does not understand that the effect was a slide.

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

19 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

Related Questions

Touch deltaPosition Android 1 Answer

Ragdoll 2D character controller help 0 Answers

Touch and Drag for Android problem 0 Answers

How to change the scaling of a gameobject during runtime? 2 Answers

I'm not sure how to approach this. 2 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