开发者

2D distance constraint

开发者 https://www.devze.com 2023-02-13 07:13 出处:网络
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

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?


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]

0

精彩评论

暂无评论...
验证码 换一张
取 消