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 MrHero · Nov 06, 2014 at 07:31 PM · mousemousepositionrotating

rotating to mouse location

i tried to rotate the arm in my main character to the mouse location but instead my code manges to rotate it in some weird direction 'when the character' moves only.. note: im not sure if this will make a difference but i have a static main camera (not moving)

alt text

problem1.png (18.6 kB)
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
1
Best Answer

Answer by robertbu · Nov 07, 2014 at 06:40 AM

This may not be your issue, but the code you have here will only work for an Orthographic camera. This:

  Camera.main.ScreenToWorldPoint(Input.mousePosition)


...will always return the position of the camera for a perspective camera. For a perspective camera, you will need to set the 'z' parameter to a distance in front of the camera. So assuming the distance you wanted was 10, you would do:

 Vector3 pos = Input.mousePosition;
 pos.z = 10.0f;
 Vector3 difference = Camera.main.ScreenToWorldPoint(pos) - transform.position.
Comment
Add comment · Show 6 · 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 MrHero · Nov 07, 2014 at 09:12 AM 0
Share

thanks :D now its working fine but once the mouse gets close to the character the rotation becomes inaccurate, any ideas of why is that happening?

avatar image MrHero · Nov 07, 2014 at 09:13 AM 0
Share

Thanks for that =D now its working good but once the mouse gets close to the character the rotating is not quit accurate to the mouse location.

any idea why is that happening?

avatar image robertbu · Nov 07, 2014 at 10:25 AM 0
Share

Without seeing your code, I'm only guessing. $$anonymous$$y guess is that you did not use the correct value for 'z'. $$anonymous$$y use of 10 above was just an example.

avatar image MrHero · Nov 07, 2014 at 11:10 AM 0
Share

my camera is 15 units away in the Z , i have changed the 10 was in the example to match my camera and tried bunch of other values,

but its still.. the problem only occurs when the mouse is near the arm im trying to rotate..

avatar image MrHero · Nov 07, 2014 at 11:20 AM 0
Share

never $$anonymous$$d thanks a lot - i have tweaked something now it's all good <3 thanks a lot bro :D

Show more comments

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

2 People are following this question.

avatar image avatar image

Related Questions

How to prevent GameObject from spawning on top of each other? 1 Answer

Ray Over Mouse 1 Answer

Can I fake the mouse/touch position relative to the real mouse/touch position? 0 Answers

Rotating object using mouse movement 1 Answer

How to translate Event.current.delta to world position? 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