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 adit1 · Feb 27, 2014 at 07:13 PM · c#rotationtransformangle

How do I rotate the hook?

I have a character which throws a hook. I want the hook to rotate in the direction I'm adding velocity/specific target. I'v tried using this:

transform.TransformDirection(hookDirection);

hookDirection is the direction of target or the velocity I'm throwing. I'm calling it when I'm pressing the input. It's not working as I expected. What am I missing here? Any help?

Edit: I'm looking for immediate rotation. It's a 3d game and the z-axis negative in forward direction.

Comment
Add comment · Show 2
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 robertbu · Feb 27, 2014 at 07:16 PM 1
Share

'Transform.TransformDirection()' takes a direction in local coordinates and convert that direction into world coordinates. It has no impact on the rotation of an object. In addition, the way based on the way you describe it, 'hookDirection' is already in world coordinates. As for what you are trying to do, whoever answers will need some information:

  • An immediate rotation (as when you launch) or a rotation over time?

  • If a 3D app, did you model your hook so that the 'forward' side of the hook is facing positive 'z' when the rotation is (0,0,0)?

  • If a 2D app, did you model your hook so that the right side is the sprite is forward?

avatar image adit1 · Feb 27, 2014 at 07:18 PM 0
Share

I've edited the additional info, thanks!

1 Reply

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

Answer by robertbu · Feb 27, 2014 at 07:25 PM

You can use:

 transform.rotation = Quaternion.LookRotation(-hookDirection);

If you are Instantiating the object, you can use the the Quaternion call in the Instantiate() call. The negative sign is because you say the 'forward' is facing negative 'z'.

Comment
Add comment · Show 4 · 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 adit1 · Feb 27, 2014 at 07:36 PM 0
Share

The z angle is somehow not correct, x and y angles are good. I checked it by pausing the scene. When I adjusted the z angle, it looks fine. What about if I have no target? should the hookDirection can be velocity direction?

avatar image robertbu · Feb 27, 2014 at 07:57 PM 1
Share

Is the 'z' angle off by 180 degrees or by something random? Unity wants the 'forward' of an object to be facing positive 'z' when the rotation is (0,0,0), and 'up' to be facing positive 'y'. So if you have the option, I'd change your model in your modeling program to fit this description. It may or may not solve your 'z' rotation problem, but it will make it far easier for anyone on this list to provide you workable solutions.

Note there is an optional second parameter to LookRotation() that defines what is considered 'up' and is used (when the rotation allows) as the axis of rotation. You may need to set this second parameter to get the rotation you want. Without an understanding of how the 'z' rotation is wrong, I cannot tell how to set this second parameter.

avatar image adit1 · Feb 27, 2014 at 08:00 PM 0
Share

I'll look into that. Thanks! What about velocity direction? If I have no direction, Can I use velocity direction in LookRotation?

avatar image robertbu · Feb 27, 2014 at 09:34 PM 0
Share

The direction of your velocity will work fine, though you will have to negate it if your forward is still facing negative 'z'.

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

20 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

Related Questions

Rotate angle 0 Answers

Flip over an object (smooth transition) 3 Answers

Rotating Camera around player object 0 Answers

Getting the rotation of an object does not return correct rotation 1 Answer

Object instantiate, Projectile problems 2 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