Created
September 3, 2011 09:36
-
-
Save N-Carter/1190919 to your computer and use it in GitHub Desktop.
Adding a HingeJoint component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class StickOnContact : MonoBehaviour | |
{ | |
public Collider m_Contactor; | |
void OnCollisionEnter(Collision collisionInfo) | |
{ | |
foreach(ContactPoint contact in collisionInfo.contacts) | |
{ | |
if(contact.thisCollider == m_Contactor) | |
{ | |
HingeJoint hingeJoint = gameObject.AddComponent<HingeJoint>(); | |
hingeJoint.connectedBody = contact.otherCollider.attachedRigidbody; // OK if it's null | |
hingeJoint.axis = Vector3.right; | |
hingeJoint.anchor = Vector3.down * 0.6f; | |
JointLimits limits = hingeJoint.limits; | |
limits.min = -5; | |
limits.minBounce = 0; | |
limits.max = 5; | |
limits.maxBounce = 0; | |
hingeJoint.limits = limits; | |
hingeJoint.useLimits = true; | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment