简体   繁体   English

统一围绕局部轴旋转对象

[英]Unity rotate object around local axis

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? 我想我在这里使用了错误的转换类型,那么我应该怎么做才能使用正确的转换?

旋转1 旋转2 旋转3

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 :) 希望它能解决您的问题:)

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. 获取对象在局部z轴上的当前旋转,这是一种方法。 https://stackoverflow.com/a/47841408/228738 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 步骤2的代码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM