简体   繁体   English

Unity3D可配置关节麻烦

[英]Unity3D configurable joint trouble

I need to set up configurable joint like hinge joint, that should be like a metal beam that connect player to object, but trouble is that the player not immidiately stop when i set the anchor point and limit the axis it fly forward to object and then fall to limit, so my beam change his size from shorter to longer and it is bad.我需要设置像铰链关节这样的可配置关节,它应该像连接玩家和物体的金属梁,但问题是当我设置锚点并限制它向前飞向物体的轴时,玩家不会立即停止下降到极限,所以我的光束将他的尺寸从更短变为更长,这很糟糕。 Can you help me?你能帮助我吗?

Here the code snippet:这里的代码片段:

playerJoint.connectedAnchor = anchor.transform.position;
SoftJointLimit limit = new SoftJointLimit();
limit.limit = Vector3.Distance(anchor.transform.position, transform.position);
playerJoint.linearLimit = limit;
playerJoint.yMotion = ConfigurableJointMotion.Limited;
playerJoint.xMotion = ConfigurableJointMotion.Limited;

And then when player unpress the button the follow code is run:然后当玩家松开按钮时,运行以下代码:

playerJoint.yMotion = ConfigurableJointMotion.Free;
playerJoint.xMotion = ConfigurableJointMotion.Free;

Thanks you in advance.提前谢谢你。

This sounds a lot like a Rigidbody.interpolation problem.这听起来很像Rigidbody.interpolation问题。

In case that it's not, you should try manually changing the player's position to be the length you want.如果不是,您应该尝试手动将玩家的位置更改为您想要的长度。 Something like:就像是:

Vector3 hinge2Player = player.transform.position - anchor.transform.position;
hinge2Player = Vector3.ClampMagnitude(hinge2Player, /* [distance you want] */);
player.transform.position = hinge2Player + anchor.transform.position;

There's also a small chance that this will help, since it seems like you're trying to do something similar.还有一个小的机会, 会有所帮助,因为它好像你正在试图做类似的事情。

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

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