Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Davidesq · Mar 08, 2018 at 04:37 AM · 2dtouchmovement scripttouchphasemove object

2D touch - Why is this movement so jittery?

So I've been struggling for years on how to get an object to move relative to touch delta horizontally in a smooth way, and my best attempt so far has been this:

 if (touch.phase == TouchPhase.Moved)
            transform.Translate(new Vector3(((touch.deltaPosition.x/screen.x) * velocityConstant * Time.deltaTime), 0, 0));
 

What I've done here: the ratio of the deltaPosition over screen.x pixel count is to normalize deltaPosition across screen sizes, and velocityConstant is a multiplier to move the object further than the actual movement.

Nonetheless, it is jittery, unpredictable and very, very inconsistent. All in all it doesn't behave like it should.
All I need is a movement relative to finger slide that moves further than the actual touch slide (hence why I say it's "relative" and not the exact length).

Any help is appreciated.

Comment
Add comment · Show 4
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 Kryloth · Mar 08, 2018 at 04:52 AM 0
Share

Can you post a screenshots on what the game look like and how the object is moving ?

avatar image Davidesq Kryloth · Mar 08, 2018 at 05:29 AM 0
Share

I could try to capture it later. But for now I can add that I feel like the speed fluctuates unpredictably - i.e.: I move my finger similar distances twice, but on one instance it moves normally and in the other is slower or faster, especially when it changes direction. The differences aren't big, nonetheless noticeable and really kill the gameplay. I would just like to know if the code is "right" so I could look for other causes for this weird behavior.

avatar image Kryloth Davidesq · Mar 08, 2018 at 06:27 AM 0
Share

Okay so, basically you're trying to make an object moving when you Hold and swipe your finger on the screen right ?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Raimi · Mar 08, 2018 at 05:21 AM

When you use a multiplier on any movement it will cause some jitteryness. The bigger the multiplier, the bigger the jitteryness. This is happens because the object is jumping by the multiplier amount each frame.e.g if the multiplier is three, it will move by 3*time.deltatime each frame, so if its 10 you can imagine whats happening.

Also, instead of using translate, modify the transform directly or use vector3.lerp.

hope it helps

Comment
Add comment · Show 2 · 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 Davidesq · Mar 08, 2018 at 07:06 PM 0
Share

Great info, I'll change it up and see how it behaves. Thanks

avatar image Davidesq · Mar 25, 2018 at 08:14 PM 0
Share

Late response: set it to directly change the transform via this:

 transform.position = new Vector3(startPos.x + ((touch.deltaPosition.x / screen.x)*velocityConstant*Time.deltaTime), startPos.y, 0);

It now moves butter smooth, thanks!

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

172 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D android swipe movement,2D Mobile Movement 0 Answers

Any one help me in this script? 0 Answers

How can i move just one object ? 0 Answers

Is my Touch Algorithm right? 0 Answers

How can I determine the speed of my touch movements? 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