Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 CrispyArrow · Dec 05, 2015 at 06:18 PM · addforcedrag

Drag and release mouse to Add forc to object's X and Y axis' only?

I've been stuck with this for a while. I've searched through the web but I can't seem to find anything related to it. I have a game object that can be pressed with the mouse/finger, when you do, you hold it and start dragging, upon release, the object will be shot towards the direction opposite of where your mouse was when releasing th drag. Considder it kind of a slingsshot effect without an actual slingshot.

My main concern as of now is what functions to use. Should I use onmousedown,onmousedrag and onmouseup or should i be using ondrag handlers?

Also, it is worth mentioning i'm not trying to make a beautiful angle, simply give the object force on it's Y and X axis' only. the gravity of the rigidbody will take care of the angle

Here's a visual example: alt text

img.png (12.3 kB)
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 Guppie1337 · Dec 06, 2015 at 05:03 AM 0
Share

You could possibly store the position of where the mouseDown action happened, then store a second position where the mouseUp action happened. After you do that, calculate the angle those 2 points make relative to the horizontal plane.

2 Replies

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

Answer by hubi037 · Dec 06, 2015 at 02:41 PM

My suggestion would be to save the start position in your mouse down function and then compare it with the current position in your mouse up function. Simply calculate the vector between them like this:

 Vector2 direction = startPosition - currentPosition;

You can also then get the length of that Vector with

 float length = direction.magnitude

and use that length for your force calculations.

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

Answer by kidmosey · Dec 06, 2015 at 08:47 AM

Drag() is useful if you want to share this object with another, like dropping it onto that object.

If all you are doing is monitoring the pointer position, you can do so within the object as long as the mouse is down. So you can set a boolean on mouse down, monitor the mouse move events or draw a line in Update() if the boolean is true.

You will also receive a MouseUp() event even if the cursor is outside of the object, so long as the MouseDown() event was triggered inside that object.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Acceleration with drag 1 Answer

Why is there still drag when drag is 0? 0 Answers

Realistic methods of propulsion without friction involved 0 Answers

Is it possible to have slow acceleration and high drag at the same time? 0 Answers

Physics are different in Build and Editor 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