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 ();
gameObject.GetComponent ().connectedBody = other.gameObject.rigidbody2D;
gameObject.GetComponent ().collideConnected = true;
//hingjoint1.anchor = pos;
gameObject.GetComponent ().anchor = pos;
//gameObject.GetComponent ().connectedAnchor = pos;
//gameObject.GetComponent ().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);
}
}
}
↧