Quantcast
Channel: Questions in topic: "attach"
Viewing all articles
Browse latest Browse all 168

Add a joint at collision point between two objects. (SteamVR held object interacting with a hinged object)

$
0
0
How can one attach a held object to a movable object in Steam VR? For example Lets say I pick up an item with the Steam VR [throawable][1] script, This item has a way to grab another object such as a hook or pincer. Once I am holding this object I would like to be able to collide with a large overhead (Normally out of reach) lever (With a [linear][2] or [circular][3] driver or a hing joint). The lever would swing around on one side while rotating it with the held object on the other side. Any ideas on how this might be done? Update: I am trying ↓ this ↓ with no luck. using UnityEngine; public class TaggedCollisionJoint : MonoBehaviour { public string linkLayerTag; public float forceToBreak = 50; public float torqueToBreak = 50; // Start is called before the first frame update and allows the script to be disabled in the inspector. void Start() { } void OnCollisionEnter(Collision col) { // Set a tag to make the conection selective. if (col.gameObject.tag == linkLayerTag) { //This ↓ works to make a solid connection between the tool and lever but breaks the lever off its joint. //col.transform.parent = transform; //This is not making a joint at all? // create a joint -Tested with character, configurable, hinge and spring joints, but no joint is made. CharacterJoint joint = gameObject.AddComponent(); // sets joint position to point of contact joint.anchor = col.contacts[0].point; // conects the joint to the other object joint.connectedBody = col.contacts[0].otherCollider.transform.GetComponentInParent(); //Set the forces which will break the joint. joint.breakForce = forceToBreak; joint.breakTorque = torqueToBreak; // Stops objects from continuing to collide and creating more joints joint.enableCollision = false; } } } [1]: https://github.com/ValveSoftware/steamvr_unity_plugin/blob/master/Assets/SteamVR/InteractionSystem/Core/Scripts/Throwable.cs [2]: https://github.com/ValveSoftware/steamvr_unity_plugin/blob/master/Assets/SteamVR/InteractionSystem/Core/Scripts/LinearDrive.cs [3]: https://github.com/ValveSoftware/steamvr_unity_plugin/blob/master/Assets/SteamVR/InteractionSystem/Core/Scripts/CircularDrive.cs

Viewing all articles
Browse latest Browse all 168

Trending Articles