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 MasterB · Apr 17, 2013 at 03:51 PM · cursormousepositioncursor-customizationmousemove

Glue mouse to object

Hey everyone, is it possible to fixate a cursor to certain XY-coordinates, as long as it remains in a specified area? I want to "jump" from the center of one game object to the center of another game object when a XY-threshold is reached. Do you have any suggestions? Regards!

Comment
Add comment · Show 3
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 Glister · Apr 17, 2013 at 05:05 PM 0
Share

I haven't done anything like this but you can gain access to the cursor position through the .Net api from there it is only a matter of setting up the logical statements for control how you want to be able to move the mouse.

If I understand correctly you want the mouse locked to one position but when they attempt to move a certain speed or a certain distance you want it to snap to the next game object?

If this is true it would seem that you will run into a problem since keeping the mouse snapped to one position you will effectively stop any input from it so it will not ever be in motion away from the original target.

What are you trying to accomplish with having the mouse stay locked to one target? $$anonymous$$aybe we can help with a solution that address with that issue.

avatar image MasterB · Apr 19, 2013 at 06:54 AM 0
Share

Basically it's about gesture-input. To compensate for the inaccuracy of the finger gesture, I want to snap the cursor to the nearest neighbour. I understand the problem you described, but Dracorat mentioned it was possible to decouple a software cursor from mouse input..

avatar image Glister · Apr 19, 2013 at 03:40 PM 0
Share

I was thinking it might be along those lines but I wasn't sure. The basic logical outline I would go for would be some thing like.

Lock the mouse to a target the first target or starting position in the on start statement. the release the mouse so it can be dragged.

Here's where the trick will be you will need to grab the direction the mouse is going as it's being dragged. On$$anonymous$$ouseUp you will do a raycast in that direction to return the closest item. You may want to do a ray cast of all items in a certain arc and return the closest one. The arc will compensate for if the user is just a little off of the target.

Then when the transform gets returned from the new target in the direction they were moving the mouse you can check whether that is X distance (X being the threshold) from the last locked targets transform. If it was greater than X then they passed the threshold and the mouse would get snapped to the new targets transform position. If the threshold was not exceeded the mouse would snap back to the original target.

In this setup the cursor actually moves but snaps either to a new target or back to the old one.

If you really want the mouse to appear not to move you should be able to just draw a custom image of the cursor at the Currently Locked position and then just use the CursorVisible from .net to make the real mouse cursor invisible and then do the same thing I was just explaining above with raycast. The only difference being that when you snap the mouse to the new position you would also draw your custom cursor at the new position and destroy the one at the old location.

If you are leaving the real cursor invisible you would still want to have it snap to the new or back to the old position to give the user the appropriate point of reference where to move the mouse from and keep from breaking the raycast.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by greatwhiteshark17283 · Apr 17, 2013 at 04:54 PM

If you are using the First Person Controller, make the camera a parent of the 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
avatar image
0

Answer by Dracorat · Apr 17, 2013 at 05:08 PM

You'll have to:

Use a software mouse cursor (required). You'll use a blank image so that nothing is actually drawn.

Decouple the position of the cursor from the position of the mouse.

Draw the mouse cursor manually (with something like a GUI.DrawTexture).

In short, you'll do a raycast each frame. If the raycast "hits" on of your desired snap points (you can use a sphere collider if you like) then you draw the cursor on the object hit. If it doesn't hit a collider, you draw the cursor at the location of the mouse.

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

14 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

Related Questions

Folow mouse script 0 Answers

How To Check Which Side of The Screen Your Cursor Is On? 1 Answer

Changing Color of Curser 2 Answers

How do I define the SetCursor Script? 1 Answer

Make GameObject match the position of mouse cursor? 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