Unity3D可配置关节问题

Unity3D configurable joint trouble

我需要设置像铰链关节这样的可配置关节,它应该像连接玩家和物体的金属梁,但问题是当我设置锚点并限制它飞行的轴时,玩家不会立即停止向前移动到物体然后下降到极限,所以我的光束将他的尺寸从短变为长,这是不好的。你能帮帮我吗?

这里是代码片段:

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;

然后当玩家按下按钮时,下面的代码是 运行:

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

提前致谢。

这听起来很像 Rigidbody.interpolation 问题。

如果不是,您应该尝试手动将播放器的位置更改为您想要的长度。类似于:

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

也很有可能会有所帮助,因为看起来您正在尝试做类似的事情。