如何在游戏中放大布娃娃 - Unity
How to enlarge a ragdoll in game - Unity
我有一个布娃娃。我想在游戏模式下增加这个布娃娃的规模。但是,当我增加比例时,布娃娃的骨头会混合并流口水。我怎样才能防止这种情况发生?相关图片如下。
Normal Scale
3x Scale
欢迎来到 Whosebug。在 Google 上快速搜索后,我为您找到了答案:
http://answers.unity.com/answers/1556521/view.html
TL;DR: 关节仅在开始时计算锚点,但以后永远不会更新。要让它们稍后更新,只需重新分配它们
Transform[] children;
private Vector3[] _connectedAnchor;
private Vector3[] _anchor;
void Start()
{
children = transform.GetComponentsInChildren<Transform>();
_connectedAnchor = new Vector3[children.Length];
_anchor = new Vector3[children.Length];
for (int i = 0; i < children.Length; i++)
{
if (children[i].GetComponent<Joint>() != null)
{
_connectedAnchor[i] = children[i].GetComponent<Joint>().connectedAnchor;
_anchor[i] = children[i].GetComponent<Joint>().anchor;
}
}
}
private void Update()
{
for (int i = 0; i < children.Length; i++)
{
if (children[i].GetComponent<Joint>() != null)
{
children[i].GetComponent<Joint>().connectedAnchor = _connectedAnchor[i];
children[i].GetComponent<Joint>().anchor = _anchor[i];
}
}
}
请确保仅在需要时才进行此重新分配,因为这会影响您的表现...
我有一个布娃娃。我想在游戏模式下增加这个布娃娃的规模。但是,当我增加比例时,布娃娃的骨头会混合并流口水。我怎样才能防止这种情况发生?相关图片如下。 Normal Scale 3x Scale
欢迎来到 Whosebug。在 Google 上快速搜索后,我为您找到了答案: http://answers.unity.com/answers/1556521/view.html
TL;DR: 关节仅在开始时计算锚点,但以后永远不会更新。要让它们稍后更新,只需重新分配它们
Transform[] children;
private Vector3[] _connectedAnchor;
private Vector3[] _anchor;
void Start()
{
children = transform.GetComponentsInChildren<Transform>();
_connectedAnchor = new Vector3[children.Length];
_anchor = new Vector3[children.Length];
for (int i = 0; i < children.Length; i++)
{
if (children[i].GetComponent<Joint>() != null)
{
_connectedAnchor[i] = children[i].GetComponent<Joint>().connectedAnchor;
_anchor[i] = children[i].GetComponent<Joint>().anchor;
}
}
}
private void Update()
{
for (int i = 0; i < children.Length; i++)
{
if (children[i].GetComponent<Joint>() != null)
{
children[i].GetComponent<Joint>().connectedAnchor = _connectedAnchor[i];
children[i].GetComponent<Joint>().anchor = _anchor[i];
}
}
}
请确保仅在需要时才进行此重新分配,因为这会影响您的表现...