- Home /
Grab rigidbody
Hey guys I have this script attached to a gameobject that i want to be picked up by my character ragdoll BUT ...instead of putting this script in every single object that i want my character to interact with i would prefer to make it so that i can just put it to my character hands.,..and from there to shoot a ray that spots ANY rigidbody and then creates the joint from the hand to the rigidbody!
I VE TRIED NUMEROUS WAYS OF DOING IT AND I CANT FIND A SOLUTION! PLEASE HELP! :/
> using System.Collections;
>
> using System.Collections.Generic;
>
> using UnityEngine;
>
> public class grab : MonoBehaviour
>
> {
>
> // Start is called before the first
> frame update
>
> public Animator anim;
>
> public int BreakF = 50;
>
> public int BreakT = 50;
>
> void OnCollisionEnter(Collision col)
>
> {
>
> if (col.gameObject.tag == "hand" &&
> anim.GetBool("IsGrab")==true)
>
> { // creates joint
>
> FixedJoint joint =
> gameObject.AddComponent<FixedJoint>();
>
> // 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<Rigidbody>();
>
> // Stops objects from continuing to
> collide and creating more joints
>
> joint.enableCollision = false;
>
> joint.breakForce = BreakF;
>
> joint.breakTorque = BreakT;
>
> }
>
> }
Comment