- Home /
Using a ConfigurableJoint to move an object to a postion and rotation.
I have input from various motion controls which essentially give me a position and rotation. I found using kinetic based rigid bodies to be disappointing, they had lots of tunneling and the controlled object could punch through anything it encountered. I'd much rather use forces to guide an object through space to orient itself in line with the inputs.
I thought the configurable joint would be the appropriate thing to use, it hooks into PhysX and uses springs and the physics solver. And would presumably be better than me hand rolling forces and throwing them at PhysX. When I hand roll tracking forces, it tracks through space just fine, but if I push against objects the object begins to jitter.
So I attempted to first, just move towards the position and ignore rotation.
If I add a ConfigurableJoint and set its x,y,z motion to Limited, and change all of its x/y/z Drives to Position based with a damper of 10 and a spring of 100. Changing "targetPosition" makes absolutely nothing move.
Constraint = gameObject.AddComponent<ConfigurableJoint>();
Constraint.xMotion = ConfigurableJointMotion.Limited;
Constraint.yMotion = ConfigurableJointMotion.Limited;
Constraint.zMotion = ConfigurableJointMotion.Limited;
Constraint.angularXMotion = ConfigurableJointMotion.Locked;
Constraint.angularYMotion = ConfigurableJointMotion.Locked;
Constraint.angularZMotion = ConfigurableJointMotion.Locked;
JointDrive drive = new JointDrive();
drive.mode = JointDriveMode.Position;
drive.positionDamper = 10;
drive.positionSpring = 100;
Constraint.xDrive = drive;
Constraint.yDrive = drive;
Constraint.zDrive = drive;
The documentation is stupidly light on this class, what do I do?
I have been having similar trouble, I am not sure what I did different, but I have been able to get it to move. Also, it appears that the target position variable acts really odd. Ins$$anonymous$$d of setting the position it deter$$anonymous$$es how far in what direction the joined object moves towards. If you ever figure it out it would be awesome if you posted your solution here.
Hi unityuser94, Not to pull one of these on you ... http://xkcd.com/979/
I recently revisited this problem with no luck. However in the mean time I created a function that applys a force and torque every "FixedUpdate ()" that moves an object to a position and rotation, however because it's not a spring based solution it can have dubious results when put put under stress...
Anyhow its pasted over here. http://pastie.org/8000460
If I ever do figure out how to get a Configurable Joint to behave as the documentation advertises, I'll be sure to post it.
O_O that was fast, and the xkcd totally describes the situation here, except it seems we have a solution. Thanks for the code, I didn't expect a response with a solution so fast. If I ever find a configurable joint solution Ill post it here as well, though from the tests i did, it doesn't look like they are going to want to do that.
The guys at PhysX came up with the worst possible design imaginable. Figuring out anchor positions and rest rotations was enough of a headache... Target Position seems to be a completely lost cause - utterly broken, utterly useless. The only cure is to have your rigidbody joined to a kinematic rigidbody with a target position of 0,0,0, and then set the world position of it. -cries-
Your answer
Follow this Question
Related Questions
Configurable Joint referencing from scrip 1 Answer
OnJointBreak 1 Answer
Calling OnJointBreak on Connected body 1 Answer
How to apply joint's inverse forces to another body 1 Answer
Joint system scale problems 2 Answers