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 salihgireniz · Apr 17, 2021 at 06:20 PM · 3dspeedmousepositiondrag-and-drop

Drag-and-drop gameObject inversely proportional to mouse speed?

I was trying to move an object by dragging the mouse. I can do it properly but I realize that if I drag the mouse so fast, it also makes the object move so fast and the objects collider does not work properly.

In that case, I have wondered how to make an object move with a speed which is inversely proportional to mouse speed. I mean, if I drag very fast, object moves toward the mouse point BUT SLOWLY.

As an example, you can check the Picker 3D player mechanic.

The Code I was using:

 private void FixedUpdate()
     {
         if (Input.GetMouseButtonDown(0))
         {
             playerZPosition = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;
 
             offSet = gameObject.transform.position - GetMouseAsWorldPoint();
         }
         if (Input.GetMouseButton(0))
         {
             float mouseSpeed = Mathf.Abs(Input.GetAxis("Mouse X"));
             playerZPosition = (Camera.main.WorldToScreenPoint(gameObject.transform.position).z) / (mouseSpeed + 1f);
             Debug.Log(playerZPosition);
             float x = Mathf.Clamp(GetMouseAsWorldPoint().x + offSet.x, -BORDER_ON_X, BORDER_ON_X);
             transform.position = new Vector3(x, transform.position.y, transform.position.z);
         }
     }
 
     Vector3 GetMouseAsWorldPoint()
     {
         // Pixel coordinates of mouse (x,y,z)
         Vector3 mousePos = Input.mousePosition;
 
         // z coordinate of game object on screen
         mousePos.z = playerZPosition;
 
         // Convert it to world points
         return Camera.main.ScreenToWorldPoint(mousePos);
     }


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 AndBje · Apr 17, 2021 at 10:26 PM 0
Share

Not an answer to your question, but a solution to your problem.

@joshuapeacock has a very nice solution to get the collisions without slowing down. You simply cast a ray from your current position to the mouse position. If the ray hits a collider, we stop at the collider, otherwise, we move to the mouse position.

https://answers.unity.com/questions/960427/rigidbodymoveposition-skips-collisions.html

0 Replies

· Add your reply
  • Sort: 

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

148 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

Related Questions

How to align x-axis movements with mouse x movement. 0 Answers

2d mouseposition in a 3d world 3 Answers

Cannot limit velocity when using tilt acceleration 1 Answer

Drag and Drop lagging behind mouse 0 Answers

How to make player's projectiles move to the mouse click position in a 3D top down shooter game? 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