0

I am trying to rotate an object around it's local axis (In this case a humanoid index finger) with my custom editor.

public float amount;

void OnGUI() {
    amount = EditorGUILayout.Slider("Rotate Amount", amount, 0, 100);
    index1.transform.localEulerAngles = new Vector3(0, 0, amount);
}

The issue I am having is when I move the slider, the finger rotates down and forward so the tips of the fingers point outwards, when in theory they should point towards the elbow.

I think I am using the wrong type of transform here, so what should I do to use the right transform?

Rotation 1 Rotation 2 Rotation 3

2
  • I think screenshots would be great here, including the axes of the object. It's hard to visualize which directions you mean. (You have tried x, y, and z, right?) Commented Sep 22, 2015 at 21:38
  • I have added the images, and I have tried all axises Commented Sep 22, 2015 at 21:51

2 Answers 2

1

Try to use:

index1.transform.Rotate(new Vector3(0, 0, amount), Space.World);

or

index1.transform.Rotate(new Vector3(0, 0, amount), Space.Self);

Hope it solves your problem :)

Sign up to request clarification or add additional context in comments.

2 Comments

Tried the negated value, 0 to -100?
That will just rotate it the other way
0

There may be 2 parts to this:

  1. Getting the current rotation of the object on the local z-axis, here's one way to do that. https://stackoverflow.com/a/47841408/228738
  2. Using the current rotation value to find the amount of rotation to apply to the object.

code for step #2

var currentZEuler = zRotation(this.transform.rotation).eulerAngles.z;
var deltaZEuler = amount - deltaZEuler;
index1.transform.Rotate(0, 0, deltaZEuler, Space.Self);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.