Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 tyxman · Jul 30, 2015 at 07:37 PM · rotationquaternion2d-platformerpivotz-axis

[2D] Player's arm following the mouse

So as the titles says I want the players arm to pivot on his shoulder so the hand points towards the mouse. LookAt doesn't work because it tries to change the z-Axis which makes the sprite disappear I've tried other methods but can't quite figure it out.

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 etopsirhc · Jul 30, 2015 at 07:44 PM

a work around would be to after using look at move the value from z to the proper one. but that may still have issues with being the right angle. best way i know of would be to calculate the angle needed yourself. you have the x/y pos of the mouse as one point, and the x/y of the arm as a second. the straight line between the 2 points would be the hypotenuse of a right triangle, from there it's just a little bit of trig to get what you want.

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 tyxman · Jul 31, 2015 at 02:09 PM 0
Share

Ok I'm still in highschool and I haven't learnt trigonometry yet but I think the equation in code is angle = $$anonymous$$athf.asin( opposite / hypoteneuse) is that right?

avatar image etopsirhc · Aug 01, 2015 at 06:32 AM 0
Share

close, you have the opposite and adjacent already, the x and y distances between the mouse and pivot point. so the code would be float angle = $$anonymous$$athf.Atan(opposite/adjacent); to help with trig later, soh cah toa sine(op/hyp) cosine(adj/hyp) tangent(op/adj)

avatar image tyxman · Aug 08, 2015 at 02:47 AM 0
Share

It's been a while but that all works with the math but the mouse position doesn't work right how do you get the position properly.

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

22 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

Related Questions

How do I make an angle with the X axis, Y axis, and Z axis and not rotate AROUND the axis? 0 Answers

Turret rotation with a pivot? 1 Answer

How to compare rotation position with an Int value (2D game) 1 Answer

Trouble - Limit rotation on Z-axis 0 Answers

Quaternions acting up 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