- Home /
Attaching a joint on the instantiated object and connecting it with the collided object.
I am trying to instantiate an object which is going to be connected to the object it hit, the problem is that I don't know how to execute this in the following script that I have made. It shows an error at line 13: BCE0020: An instance of type 'UnityEngine.Joint' is required to access non static member 'connectedBody'.
I have a feeling that even if that error is dealt with, the script is probably wrong either way.
var ImpactSite: GameObject;
function OnCollisionEnter(collision : Collision) {
for (var contact : ContactPoint in collision.contacts)
{
if(contact.otherCollider.gameObject.name.Contains("RockLevel")){
var normal = contact.point - contact.otherCollider.transform.position;
var q = Quaternion.FromToRotation(Vector3.up, normal);
Instantiate(ImpactSite, contact.point, q);
ImpactSite.AddComponent(FixedJoint);
var otherBody = contact.otherCollider.gameObject.Rigidbody;
FixedJoint.connectedBody = otherBody;
Destroy(this);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613140515im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Making the collider change after being instantiate 2 Answers
"Destroy" bullet without turning off trail renderer 2 Answers
Raycast bullet impact and instantiating particles 3 Answers
BoxCollider2D failling verification when Instantiate (Fixed, Cause: big derp) 1 Answer
conditional gameobject spawning from collision array help please? 1 Answer