- Home /
How do I connect FixedJoints on collision
I made this script and it some times works but usually it doesn't.
heres the script using UnityEngine; using System.Collections;
public class Pyhsics : MonoBehaviour
{
private bool attatched = false;
public Rigidbody rigbody;
void OnCollisionEnter(Collision col)
{
if(attatched == false)
{
if(col.collider.gameObject.tag == "Finish")
{
if(col.collider.gameObject.GetComponent<FixedJoint>() == null)
{
col.gameObject.AddComponent("FixedJoint");
}
FixedJoint Join = transform.gameObject.GetComponent<FixedJoint>();
if(Join.connectedBody == null)
{
FixedJoint J = col.gameObject.GetComponent<FixedJoint>();
J.connectedBody = rigbody;
J.breakForce = 8;
J.breakTorque = 8;
if (col.relativeVelocity.magnitude > 20)
audio.Play();
}
}
}
}
}
some
others
Answer by Josh1231 · Aug 09, 2014 at 05:40 PM
I think you wanted both of them to have the same connected body, so you should have done
Join.connectedBody = col.rigidbody;
Join.breakForce = 8;
Join.breakTorque = 8;
To make it set itself, if this isn't what you wanted, please explain it more so I can tell you what to do.
You also never change attached to true, i don't know if there is more to the code to do that, but you may want to do that in the enter where all of the connected body is put to make sure that it doesn't change it's connected body.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
How do I connect two objects together in the scene? 1 Answer
Attaching objects on collision 1 Answer
Collision on specific Frames 1 Answer