Пример #1
0
    // Use this for initialization
    void Start()
    {
        RB = gameObject.transform.GetChild(1).gameObject;
        LB = gameObject.transform.GetChild(2).gameObject;
        LT = gameObject.transform.GetChild(3).gameObject;
        RT = gameObject.transform.GetChild(4).gameObject;

        body = gameObject.transform.GetComponent <Rigidbody>();
        body.maxAngularVelocity = MaxAngularVelocity;

        joints  = GetComponents(typeof(ConfigurableJoint));
        RBjoint = (ConfigurableJoint)joints[0];
        LBjoint = (ConfigurableJoint)joints[1];
        LTjoint = (ConfigurableJoint)joints[2];
        RTjoint = (ConfigurableJoint)joints[3];

        RBobj = RB.GetComponent <playerChildren>();
        LBobj = LB.GetComponent <playerChildren>();
        RTobj = RT.GetComponent <playerChildren>();
        LTobj = LT.GetComponent <playerChildren>();

        RBgrabbing = false;
        LBgrabbing = false;
        RTgrabbing = false;
        LTgrabbing = false;

        buttons          = buttonsTrans.GetComponent <buttonController>();
        gameInputManager = GameInputManager.instance;
    }
Пример #2
0
    //update the corner's joint and velocity
    private void updateJointAndVelocity(bool pressed, ref bool grab, ref playerChildren obj, ref ConfigurableJoint joint, int YaxisFix = 1)
    {
        bool sideGrabL = false;
        bool sideGrabR = false;

        //unlocking the grab if the user lets go of the button
        if (!pressed && grab)
        {
            grab = false;
            joint.connectedBody = null;
            joint.xMotion       = ConfigurableJointMotion.Free;
            joint.yMotion       = ConfigurableJointMotion.Free;
            joint.zMotion       = ConfigurableJointMotion.Free;
        }
        //creating a new attached body when the user initially grabs a corner to a surface or item
        else if (!grab && obj.canGrab && pressed)
        {
            grab = true;
            joint.connectedBody = obj.grabbableBody;
            joint.xMotion       = ConfigurableJointMotion.Locked;
            joint.yMotion       = ConfigurableJointMotion.Locked;
            joint.zMotion       = ConfigurableJointMotion.Locked;
        }
        //checking if the user is grabbing with the left or right side of the item
        else if (grab)
        {
            //first check top, bottom, and side grabs
            if (LTgrabbing && LBgrabbing)
            {
                //angular
                sideGrabL = (checkGrab(LTjoint) && checkGrab(LBjoint)) || LTjoint.connectedBody == LBjoint.connectedBody;
            }
            if (RTgrabbing && RBgrabbing)
            {
                //angular
                sideGrabR = (checkGrab(RTjoint) && checkGrab(RBjoint)) || RTjoint.connectedBody == RBjoint.connectedBody;
            }

            //apply the correct oriented angular velocity
            applyMovement(sideGrabL, sideGrabR, YaxisFix);
        }
    }