- Home /
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).
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.
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
Dude, check the docs if u don't know proper syntax on a function :D
Javascript:
transform.localEulerAngles = Vector3(0.0, 45.0, 0.0);
transform.localRotation = Quaternion.Euler(0.0, 45.0, 0.0);
How would you "maintain your own Vector3" for eulerAngles?
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
@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
Follow this Question
Related Questions
Object rotating around object at two levels 1 Answer
Problem with Constraint Camera Rotation C# 3 Answers
Rotating an already rotated object. 1 Answer
really annoying rotation problem. 0 Answers