- Home /
Joints Configured from Script do not work properly? $20 reward
I desperately need to be able to create joints via script. Currently I add and then set them up and they sort of work but something is clearly wrong, Motion and Angular Motion that are supposed to be locked are not locked, PositionSpring can only add a weak amount of force and position damper actually reduces that force without actually adding any damper.
Duplicates of these assemblies actually get progressively worse. I've tried setting .active to false just before and after .AddComponent with no effect. I have the same problem instantiating prefabs with joints, and creating joints via the editor with the game running.
Is there no way to add a Configurable Joint with the game running?
$20 Bounty for a solution to this.
Answer by Jean-Fabre · Jan 05, 2012 at 04:12 PM
Hi,
Totally feasible. I made a demo last year with an excavator fully scripted, building joints and setting them up on the fly.
http://www.fabrejean.net/projects/excavator/
Bye,
Jean
Answer by taters · May 25, 2011 at 02:29 PM
I'm actually having a similar issue, but I have got as far as adding the joint. It's just the drive settings etc just dont 'stick'.
Here is my code that adds a config joint o.k. It's just that setting the angularXDrive and spring dont seem to do anything.
You can download my test scene here, it may be a good starting point. At least the joints are being added!
If you figure a way to make the angularXDrive and spring stick when done through script, please let me know!!
Dave
Answer by dear_gamemaster · Nov 28, 2011 at 05:36 AM
I do it like this (in a collision example):
function OnTriggerEnter(collision : Collider) {
var joint : FixedJoint = gameObject.AddComponent(FixedJoint);
joint.connectedBody = collision.gameObject.rigidbody;
joint.breakForce = 250;
joint.breakTorque = 250;
}
Don't create and add a joint from scratch, let AddComponent(FixedJoint) create it and return it, then define it's values and there you are. In this example, it's working with a fixed joint, but I tested it out and it's working with any of the predefined ones.
Answer by inum76 · Oct 07, 2015 at 01:19 AM
I found while using scrips, C#, The Rigidbody falls asleep. You need to wake it up within the script during each update. It is a bad idea to mess with a Quaternion directly. You should set XYZ in Euler angles with a vector3. public Vector3 Vec1; Then you set your Quaternion with it, this way: private Quaternion QVec1; QVec1 = Quaternion.Euler (Vec1); QVec1 would be your set Quaternion with the angles you wish it to have. This is my vid on the subject you ask about, if you wish to check it out. Link: ConfigurableJointScript 1 The vid tells how to properly set TargetRotation within a script, and have it work! Hope this helps. Oh' you can keep you $20 if it does help you. :)
Your answer
Follow this Question
Related Questions
controlling the target rotation of a configurable joint via input? 1 Answer
Difference between creating Configurable Joint in code and creating the same type of Joint in script 1 Answer
Dynamically create GUIText from script. 2 Answers
Attaching a Hinge Joint upon colliding with a rigidbody. 1 Answer
Joint: Swing & Twist? 1 Answer