2D距离约束
我一直在尽一切努力让 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道这并不是真正的答案,但添加评论按钮不存在。我很擅长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]