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 /
  • Help Room /
avatar image
0
Question by whynot660 · Jan 31, 2017 at 02:05 PM · gameobject2d gamecursor-customizationspeed upspeed issues

game object attached to the cursor moving too slow

Hi, I'am trying to create a 2d gameObject containing a Sprite and a collider to replace the default cursor. To keep the game object at the cursor position I wrote a script that changes the gameObject positon to the current mousePosition

 void Start () {
         tr = gameObject.transform;
         ZinitPos = 1.0f;
         curPos = new Vector3(0.0f, 0.0f, 0.0f);
     }
     
 
     void Update () {
         curPos = Input.mousePosition;
         curPos.z = 1.0f;
         tr.position =     Camera.main.ScreenToWorldPoint(curPos);                                   
     }

the code is working fine but the game object has some latency, it moves very slower then the cursor. I know there is some solution some where and a somebody among you smart people :]. thank you for reading and sorry for wasting your time

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

1 Reply

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

Answer by paramburu · Jan 31, 2017 at 04:03 PM

Hi, Maybe you should use unity native functionality:

https://docs.unity3d.com/ScriptReference/Cursor.SetCursor.html

Good luck!

Comment
Add comment · Show 3 · 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 whynot660 · Jan 31, 2017 at 06:40 PM 0
Share

Hi @paramburu , and thanks for the reply; I know about the SetCursor function but I'am using the cursor as a game object that contains a collider, to interact with other game objects with colliders. using the default cursor or setting up a new texture for it wouldn't help me I think since I will have to calculate the distance between the position of the cursor and all the other objects with my current modelisation I have only to use OnTrigger2DEnter/Stay/Exit() to control the game the problem is that my cursor is too slow and not moving smoothly

avatar image paramburu whynot660 · Jan 31, 2017 at 07:45 PM 0
Share

Well, the code itself seems fine. $$anonymous$$aybe you should use the profiler to see what is happening internally. I would guess that is a performance issue of having to redraw the sprite every frame + the colliders.

Try using an independent canvas for the cursor, it should be more efficient although I don't know if that will work properly with the other colliders.

Another option could be using SetCursor and 2D raycasting or SetCursor on one side and the Collider with the same code you already have but without the texture.

Hope it helps...

avatar image whynot660 · Feb 04, 2017 at 09:40 PM 0
Share

thank you for your help :)

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

110 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

Related Questions

Player Only Moves When I Touch The GameObject Directly But I Want To Touch And Move From Anywhere From The Screen,Player Moves By Touch but ONLY When I Touch The GameObject. 0 Answers

crouch attack collider 2d question 1 Answer

How To Add Multiple 2d Box Colliders on Same Object for Different Effects 0 Answers

Spawn from GameObject C# 0 Answers

How do you make a random 2D shape in Unity? 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