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
2
Question by NP-Complete · Feb 16, 2014 at 12:36 AM · transformrotate objectlocalrelative rotationcusm rotation

How do I set and get local rotation of objects

I have 3D model of robotic hand, that I want to control with C# code. I want to be giving specific rotation to fingers in range 0-90 degrees, so if I want my hand to be open, I will pass value of 0, if I want it to be closed, I will pass 90. In order to rotate the fingers properly, the rotation must be local, but I don't know how to get local rotation of object and set local rotation.

Any tips on controlling fingers in unity? (By the way, I am using glove, outside the pc, that is communicating with unity, that's why I want to set values to finger rotations and not increment or decrease using Transform.Rotate(x, y, z, Space.Self).

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
6

Answer by robertbu · Feb 16, 2014 at 12:42 AM

You can use Transform.localEulerAngles or Transform.localRotation to set the local rotation. Note that reading from eulerAngle can cause issues since there are multiple Euler representations for any given physical rotation. It is best maintain your own Vector3 and treat eulerAngles as write-only.

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 NP-Complete · Feb 16, 2014 at 12:57 AM 0
Share

Could you provide an example on how to actually use use those functions in code? I get errors because I'm not writing it correctly correctly use those localEulerAngles or localRotation functions

avatar image bennett_apps NP-Complete · Oct 08, 2018 at 11:18 PM 0
Share

Dude, check the docs if u don't know proper syntax on a function :D

avatar image robertbu · Feb 16, 2014 at 01:07 AM 0
Share

Javascript:

 transform.localEulerAngles = Vector3(0.0, 45.0, 0.0);

 transform.localRotation = Quaternion.Euler(0.0, 45.0, 0.0);
avatar image DDeathlonger · Oct 08, 2018 at 08:25 AM 0
Share

How would you "maintain your own Vector3" for eulerAngles?

avatar image Casiell DDeathlonger · Oct 08, 2018 at 09:02 AM 0
Share

If your object is not rotated by physics, only by code you can keep and modify your own rotation Vector3 variable. So for example you start from (0, 0, 0) and rotate your object by 90 degrees in X axis. You just have to add (90, 0, 0) to your rotation variable.

Best way to do this is create a method RotateLocal that will both rotate object and set your variable and use this method each time you want to rotate your object. This way you will never forget to set your variable.

$$anonymous$$eeping track of physical rotation is probably also possible, but a tad more difficult

avatar image giantkilleroverunity3d · Oct 08, 2018 at 05:52 PM 0
Share

@Casiell I like your comment. This gives flexibility and adaptability for a more natural finger movement with all fingers as a fluid movement. Like how the fingers follow each other in closing the hand. Of course there would have to be more code but that would just be routines calling routines once the individual finger code was in place.

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

Object rotating around object at two levels 1 Answer

Problem with Constraint Camera Rotation C# 3 Answers

Why is it that when I equip weapons, they rotate in different ways depending on which way I[my character-player] am[is] looking? 1 Answer

Rotating an already rotated object. 1 Answer

really annoying rotation problem. 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