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 /
avatar image
0
Question by rustofelees · Dec 21, 2015 at 07:30 AM · uivelocitymathacceleration

Getting UI into the right position after releasing drag

Hello,

I have a bit of a math problem that I'm having a hard time wrapping my head around. I'm using the event trigger OnDrag to move a piece of UI around the screen while the user is dragging a finger. I calculate the mouse position in worldspace (using cam.ScreenPointToWorld), subtract the previous mouse position in worldspace, and then divide this value by Time.deltaTime to find the velocity of the object on a per frame basis. I then add this value to the existing UI's position in order to find the new position. (For what it's worth, I also multiple the velocity by cam.SceenPointToWorld(Vector3.right) - cam.ScreenPointToWorld(Vector3.zero)).

When the event trigger OnDragRelease is fired, I know the velocity of the UI when the finger released their finger. Now, I'd like to keep the UI element temporarily moving with the same velocity, but slow down it down as it moves toward a known position over a know number of seconds. I'm familiar with lerp, but I don't think this is what I want to use, as the change in velocity will not be linear.

Any thoughts on how to get this object to the right place, in the right amount of time, while starting with an initial velocity? Thanks in advance!

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 rustofelees · Dec 21, 2015 at 06:57 PM 0
Share

Bump. Can anyone help?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rustofelees · Dec 23, 2015 at 12:15 AM

If anyone finds this in the future I solved this problem using Vector3.SmoothDamp.

 while (startingVelocity.magnitude > .1f){
     gameObject.transform.position = Vector3.SmoothDamp(gameObject.transform.position, endPos, ref startingVelocity, .1f); 
     yield return null;
 }
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

38 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

Related Questions

How to change velocity of object which move by Rigidbody. 1 Answer

How do I create a rubber band effect on a camera forward movement? 1 Answer

Make something arrive at position in exactly X seconds? 2 Answers

Achieving consistent jump height regardless of vertical velocity 2 Answers

arrows in unity 3d? 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