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 NikEy · Oct 14, 2012 at 08:10 PM · mousecursorcontrol

Hardware accelerated mouse

Hi all,

I am trying to create an RTS. Not hiding the standard mouse cursor, I can see that the software update is lagging massively behind the hardware accelerated mouse. A simple example is to create a GUITexture and updating its position every time with new mouse input. You will notice - even with no other program code - that the texture is lagging behind the real mouse movement if you move it rather swiftly. Some people don't seem to notice it, but it drives me crazy. I checked the forums and it seems like a lot of people have the same problem - apparently Unity3D does not support hardware mouse, even though someone wrote a windows plugin for changing the cursor. Note that I need to change more than just the cursor, i.e. the selection box needs to be fluid as well, etc.

I noticed however, that in the AngryBots example the mouse does NOT lag behind the action. I can't find anything special in the code though, so my question really: What does AngryBots do to obtain a hardware accelerated mouse with custom cursors? Also, platform independence is a big thing for me, so I don't just want to tweak the user32.dll or anything similar only to achieve this for windows.

Thank you

Comment
Add comment
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

3 Replies

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

Answer by -chris · Oct 16, 2012 at 11:45 PM

Unity 4 is going to have hardware cursor support (available in the Unity 4 beta right now), so if you can wait around for that, don't worry about 3.5 software cursor issues too much.

[http://unity3d.com/unity/beta/notes][1]

New Cursor API was introduced:

- Cursor API supports both software and hardware cursors. - Support for hardware cursors on the following platforms: Windows, Mac OS X, Linux, Flash. - Configure the default cursor in your projects’ Player Settings. [1]: http://unity3d.com/unity/beta/notes
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 Eric5h5 · Oct 14, 2012 at 08:17 PM

AngryBots does not have hardware accelerated mouse support. It's not supported in Unity 3 outside of plugins.

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 NikEy · Oct 14, 2012 at 10:25 PM

So while hardware acceleration for the mouse is not part of Unity3D (thanks Eric), there seems to be a good way of simulating this to the best effect possible (at least that's the best solution I found after hours of research). Credit should go to this post for giving me the idea: http://forum.unity3d.com/threads/118864-Matching-quot-Fake-quot-Cursor-to-system-mouse-speed-(Suggestion-for-Screen.clampCursor)

In my (short) experience Input.mousePosition is generally good, however, when you are moving the mouse in a fast manner, the software cursor will be noticeably lagging behind the actual hardware cursor. You can see this by setting Screen.showCursor to True.

However, since the effect only happens during rapid movements, one can simply extrapolate from the current movement velocity in order to display the cursor at the point where the user "feels" it is. So in order to perform such a "software acceleration" you can simple lock the mouse and use the mouse delta in order to derive the current mouseposition. By then multiplying the mouse delta with a feasible value (such as 1.5) you artificially created a very smooth mouse acceleration that will sufficiently enough simulate rapid movements that are in line with the user expectation.

Here the code in C#:

 using UnityEngine;
 using System.Collections;
 
 public class MouseCursor : MonoBehaviour {
     public GameObject cursor;
     private GameObject _cursor;
     
     // Use this for initialization
     void Start () {
         Screen.lockCursor = true;
         Screen.showCursor = false;
         _cursor = (GameObject) Instantiate(cursor);
         _cursor.transform.position = new Vector3(0.5f, 0.5f, 0f);
     }
     
     // Update is called once per frame
     void Update () {
         Vector3 mouseDelta = new Vector3( Input.GetAxis("Mouse X") , Input.GetAxis("Mouse Y"), 0f ) * 1.5f;
         Vector3 pos = Camera.main.ScreenToViewportPoint(mouseDelta) + _cursor.transform.position;
         
         _cursor.transform.position = pos;
         
     }
 }
 
Comment
Add comment · Show 1 · 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 NikEy · Oct 15, 2012 at 12:14 AM 0
Share

Forgot to mention that I changed the mouse sensitivity from 0.1 to 0.5 in Edit/project settings/input prior to doing this, so that would be necessary.

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

12 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

Related Questions

How to make camera position relative to a specific target. 1 Answer

Unity 3D Screen.lockCursor Problems 2 Answers

Alt+Tab pointer problem 0 Answers

How to center custom cursor 2 Answers

error CS8025: Parsing error 1 Answer


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