2D距离约束

发布于 2024-10-19 13:35:38 字数 746 浏览 2 评论 0原文

我一直在尽一切努力让 2D 距离关节在 Unity 中工作。我希望带有关节的身体和连接的身体都能自由旋转,我还需要遵守质量和其他约束,例如固定刚体的位置。我已经尝试了好几天了,没有成功配置任何关节类型。尝试使用 Verlet 约束:

float xDistance = hinge.transform.position.x  - target.transform.position.x;
float yDistance = hinge.transform.position.y  - target.transform.position.y;
float newdistance = Mathf.Sqrt( xDistance * xDistance + yDistance * yDistance );
float con = ( newdistance - maxDistance) / newdistance;
Vector3 moveTarget = new Vector3( xDistance * 0.5f * con , yDistance * 0.5f * con, 0.0f );
hinge.rigidbody.MovePosition( hinge.transform.position - moveTarget );
target.rigidbody.MovePosition( target.transform.position + moveTarget );

但这没有考虑质量/力或任何固定装置。您可以在这里看到我想要在 X/Y 上移动并仅在 Z 上旋转。

有帮助吗?

I've been trying everything to get a 2D distance joint working in Unity. I want free rotation to both the body with the joint and the connected body, I also need mass and other constraints adhered to, such as fixing a rigidbody's position. I've tryed for days now, no luck configuring any joint type. Tryed a verlet constraint using:

float xDistance = hinge.transform.position.x  - target.transform.position.x;
float yDistance = hinge.transform.position.y  - target.transform.position.y;
float newdistance = Mathf.Sqrt( xDistance * xDistance + yDistance * yDistance );
float con = ( newdistance - maxDistance) / newdistance;
Vector3 moveTarget = new Vector3( xDistance * 0.5f * con , yDistance * 0.5f * con, 0.0f );
hinge.rigidbody.MovePosition( hinge.transform.position - moveTarget );
target.rigidbody.MovePosition( target.transform.position + moveTarget );

But this doesn't take into account mass/force or any fixtures. You can see here I want movement on the X/Y and rotation only on Z.

Help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恬淡成诗 2024-10-26 13:35:38

我知道这并不是真正的答案,但添加评论按钮不存在。我很擅长Unity,但我从未使用过Unity2D,而且我不能说我以前见过“MovePosition”。

通过在 http://answers.unity3d.com 上提问,您会更幸运地找到答案
[再次,我为这不是一个答案而道歉。我宁愿这是一条评论,但 tkat 不是一个选择]

I know this isn't really an answer, but the add comment button is not there. I'm good with Unity, but I have never used Unity2D, and I can't say I've ever seen "MovePosition" before.

You would have better luck with finding an answer by asking this on http://answers.unity3d.com
[Again, I apologize for this not being an answer. I'd rather this be a comment, but tkat isn't an option]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文