- Home /
Custom Joints
hey so im using the default unity joint but they just don't have the functionality that i need so im thinking my next best option is to create my own custom (but simpler) joints.
here is a very basic script i made trying to figure out how to do this.
public Rigidbody ConnectedNode;//connected rigidbody
public float BreakingForce = 10f;// the force that is required to break the joint
private float ForceApplyed;//this holds the force that was applyed when an object collides with it
private Vector3 RelitivePosition;//the position the object is relitive to its connected body
// Use this for initialization
void Start () {
RelitivePosition = transform.position - ConnectedNode.transform.position;//sets the relative position
}
// Update is called once per frame
void Update () {
rigidbody.MovePosition (ConnectedNode.transform.position + RelitivePosition);
rigidbody.MoveRotation (ConnectedNode.transform.rotation);
}
void OnCollisionEnter (Collision col){
if(col.rigidbody){//if we had a rigidbody
ForceApplyed = col.rigidbody.velocity.magnitude * col.rigidbody.mass;
if(ForceApplyed > BreakingForce){
//Call JointBroke Function on this object
//Call JointBroke Function on Connected node
Destroy(this);//remove the Joint
}
}
}
the main problem im having is keeping the rigid body's aligned with each other. (calculating the position of where the rigid body is suppose to be relevant to the Connected rigid body's position)
Thanks ~Scott
Your answer
Follow this Question
Related Questions
Rigidbody hover, bodies connected with joints should hover together. 0 Answers
Violent shaking when using position drive in Configurable Joints 1 Answer
Need Hinge Joint to interact with only one object, but still collide with others 0 Answers
How do I connect multiple spheres using joints and make a character? 1 Answer