- Home /
How to use Best of contactPoints2d
i am new, advanced thanks for help, i want to ask question that i am developing a game like a spider man when we throw a rope to any collider then i want that rope will be attached with hingejoint2d with that collider using contactpoints2d but i tryied my best but in vain because of limited knowledge any one help me I have watched all official tutorials also
using UnityEngine;
using System.Collections;
public class TestCollision : MonoBehaviour {
HingeJoint2D hingjoint1;
//var sparks : ParticleEmitter;
ParticleEmitter sparks;
void OnCollisionEnter2D (Collision2D other){
if (other.gameObject.tag == "tire1") {
rigidbody2D.velocity = Vector3.zero;
//*****************************************************
ContactPoint2D contact = other.contacts[0];
//contact = contact.normal;
Vector3 pos = contact.point;
gameObject.AddComponent<HingeJoint2D> ();
gameObject.GetComponent<HingeJoint2D> ().connectedBody = other.gameObject.rigidbody2D;
gameObject.GetComponent<HingeJoint2D> ().collideConnected = true;
//hingjoint1.anchor = pos;
gameObject.GetComponent<HingeJoint2D> ().anchor = pos;
//gameObject.GetComponent<HingeJoint2D> ().connectedAnchor = pos;
//gameObject.GetComponent<HingeJoint2D> ().normal = gameObject;
//******************************************************
gameObject.rigidbody2D.isKinematic = true;
//gameObject.rigidbody2D.isKinematic = false;
// var rotation = Quaternion.FromToRotation(Vector3.down, contact.normal);
//
//
// Instantiate(sparks, contact.point, rotation);
Debug.Log ("Collision Enter");
Debug.Log (pos);
}
}
}
I think your title might be misleading. Looking at your code it looks like you are having trouble positioning the HingeJoint2D. Looking at the title I first thought you didn't know which of the contact points to use ("how to select best of contactpoints" other.contacts[0] or [1] or [2]...)
Can you please clarify what your problem is.
Your answer
Follow this Question
Related Questions
Obtaining contact point and normal of first object in collision 0 Answers
Why is collision.contacts causing a compiler error 1 Answer
contact.normal not updating in OnCollisionStay2D 0 Answers
Is there any way to find the mesh triangles which are colliding with another mesh? 1 Answer
Wrong ContactPoint position when modifying velocity 1 Answer