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 /
avatar image
0
Question by RogerTheJolly · Aug 26, 2015 at 08:25 PM · unity 5unity5mousemousepositionmouse position

Unity 2d Top-Down Mouse Aiming Stutters When Moving

I'm creating a top-down that uses the mouse position to determine character and flashlight rotation. The problem is that it the aiming shakes/stutters. This is especially noticeable when the mouse is closer to the character; completely spazzing out when the mouse is directly on top of the character. I've spent some time looking for a solution and playing around on my own, but I haven't been able to find anything.

 void FixedUpdate
 {
 float fAngle;
         Vector3 pos = Input.mousePosition;
         pos.z = player.transform.position.z - Camera.main.transform.position.z;
         pos = Camera.main.ScreenToWorldPoint(pos);
         pos = pos - player.transform.position;
         fAngle = (Mathf.Atan2 (pos.y, pos.x) * Mathf.Rad2Deg);
         
         this.gameObject.transform.rotation = Quaternion.Euler(fAngle - 180, 270f, 0f);
 }

This is the code that I'm using to rotate the flashlight. The character rotation code is identical. The issue is extremely noticeable with the flashlight.

It appears that Input.mousePosition is not being updated frequently enough.

Any ideas would be greatly appreciated.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DanRigg11 · Aug 27, 2015 at 09:36 AM

hi i used this tutorial hope it helps https://www.youtube.com/watch?v=F5a4Xo6ijLE∈dex=5&list=PLBLzRnRotAkpX851-d_hEpV7dOVkCUMPF

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 jimbobulus2 · Aug 28, 2015 at 06:12 PM

Hi @RogerTheJolly Try using Update() instead of FixedUpdate(). FixedUpdate() runs at a fixed time step. Or, try adding a Lerp to the Quaternion to smooth out the animation:

 this.gameObject.transform.rotation = Quaternion.Lerp(this.gameObject.transform.rotation,  Quaternion.Euler(fAngle - 180, 270f, 0f), Time.deltaTime );

http://docs.unity3d.com/ScriptReference/Quaternion.Lerp.html

If you want to adjust the smooth speed, multiply the Time.deltaTime by something.

I also made a tutorial on rotating 2D using the z-axis with an example project that might be useful

http://blog.iss.io/?p=26

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Fill Font Characters with White? 0 Answers

Start Application on second monitor 1 Answer

Why we have to use getcomponent instead of a simple reference ? 2 Answers

Get mouse position outside of the main window 0 Answers

When I set Obstacle Avoidance Radius of NavMesh in Unity, the unit defuse to move?,I set Avoidance Radius in NavMesh Agent, and my unit refused to move? 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