public Transform realClamppedJoystickInput; // The target position for this arm tip based on the joystick input

    // Use this for initialization
    void Start()
    {
        // Set up the 2D arm
        armBodyHingeJoint2D = armBodyJoint2D.GetComponent <HingeJoint2D>();        // Get the initial hinge joint 2D on the 2D arm-body joint
        targetArmBodyHingeJointMotor.maxMotorTorque = armBodyHingeJointMotorForce; // Set the max torque of the motor on the 2D hinge joint on the 2D arm-body joint
        armBodyHingeJoint2D.useMotor  = true;
        armBodyHingeJoint2D.useLimits = false;
        armTipSliderJoint2D           = armTip2D.GetComponent <SliderJoint2D>();   // Get the initial slider joint 2D on the 2D armTip
        targetArmTipSliderJointMotor.maxMotorTorque = armTipSliderJointMotorForce; // Set the max torque of the motor on the 2D slider joint on the 2D armTip
        armBodyHingeJoint2D.useMotor = true;
        // Set the 2D armTip slider joint's translation limits
        JointTranslationLimits2D armTipSliderJointLimit = new JointTranslationLimits2D();

        armTipSliderJointLimit.min    = 0;
        armTipSliderJointLimit.max    = armMaxLength;
        armTipSliderJoint2D.limits    = armTipSliderJointLimit;
        armTipSliderJoint2D.useLimits = true;

        //CreateBackUpHingeJoint2D();

        // Set up the flags
        canGrabObject = true;

        // Set up the arm stretch limiter
        if (isLeftArm)
        {
            //armTipStretchLimiter.localScale = armTipStretchLimiter.localScale * armMaxLength * 2;
        }
    }
Beispiel #2
0
    void ConfigureWheel()
    {
        gameObject.GetComponent <SliderJoint2D>().connectedBody = Parent;
        gameObject.GetComponent <SpringJoint2D>().connectedBody = Parent;
        Wheel.GetComponent <HingeJoint2D>().connectedBody       = GetComponent <Rigidbody2D>();

        SliderJoint2D sliderJoint = gameObject.GetComponent <SliderJoint2D>();

        sliderJoint.enableCollision = true;
        sliderJoint.connectedAnchor = new Vector2(transform.localPosition.x, transform.localPosition.y);

        sliderJoint.useLimits = true;
        JointTranslationLimits2D limit = new JointTranslationLimits2D();

        limit.min          = -DamperSize;
        limit.max          = DamperSize;
        sliderJoint.limits = limit;

        SpringJoint2D springJoint = gameObject.GetComponent <SpringJoint2D>();

        springJoint.enableCollision = true;
        springJoint.connectedAnchor = new Vector2(transform.localPosition.x, transform.localPosition.y + (-DamperSize));

        springJoint.frequency = DamperStiffness;

        gameObject.transform.parent = null;
        Wheel.transform.parent      = null;
    }
Beispiel #3
0
    static int _CreateJointTranslationLimits2D(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 0);
        JointTranslationLimits2D obj = new JointTranslationLimits2D();

        LuaScriptMgr.PushValue(L, obj);
        return(1);
    }
Beispiel #4
0
 void Start()
 {
     slider           = GetComponent <SliderJoint2D>();
     lim              = slider.limits;
     speed            = (lim.max - lim.min) / period;
     m.maxMotorTorque = slider.motor.maxMotorTorque;
     m.motorSpeed     = speed * orientation;
     slider.motor     = m;
     marginTime       = 0;
     rb       = GetComponent <Rigidbody2D>();
     minSpeed = (slider.motor.maxMotorTorque / rb.mass) * Time.fixedDeltaTime;
 }
Beispiel #5
0
    void OnValidate()
    {
        //Update mouse sensitivity
        mAxis.mouseSensitivity = sensitivity;
        mAxis.smoothing        = smoothing;

        //Update Joint paramaters
        JointTranslationLimits2D l = new JointTranslationLimits2D();

        l.min = -maxArmLength;
        l.max = maxArmLength;
        armHinge.maxMotorTorque  = maxAngularForce;
        armSlider.maxMotorTorque = maxLinearForce;
    }
Beispiel #6
0
    void OnTriggerEnter2D(Collider2D col)
    {
        Debug.Log("Slider Trigger Activated");
        if (col.gameObject.tag == "Slider")
        {                               //col.gameObject.SetActive(false);
            sprenderWhiteGlow.enabled = false;
            activeSlider = col.gameObject;
            Debug.Log("Slider Activated");
            GetComponent <SliderJoint2D>().enabled = true;

            //GetComponent<SliderJoint2D> ().connectedBody = col.GetComponent<Rigidbody2D> ();
            //GetComponent<SliderJoint2D> ().anchor = col.GetComponent<Rigidbody2D> ().position;
            GetComponent <SliderJoint2D> ().connectedAnchor = col.GetComponent <Rigidbody2D> ().position;


            JointTranslationLimits2D limits = GetComponent <SliderJoint2D>().limits;
            //limits.min = -col.GetComponent<SpriteRenderer>().bounds.extents.x;
            //limits.max = col.GetComponent<SpriteRenderer>().bounds.extents.x;
            float Ex = 0.0f, Ey = 0.0f;
            float angleRot = col.GetComponent <Rigidbody2D> ().rotation;
            Ex = col.GetComponent <SpriteRenderer> ().bounds.extents.x;
            Ey = col.GetComponent <SpriteRenderer> ().bounds.extents.y;

            //
            //			limits.max = (Mathf.Cos (angleRot) * Ex - Mathf.Sin (angleRot) * Ey) / (Mathf.Cos (angleRot) * Mathf.Cos (angleRot) - Mathf.Cos (angleRot) * Mathf.Sin (angleRot));
            //				limits.min =-limits.max;
            //				GetComponent<SliderJoint2D> ().limits = limits;
            if (angleRot == 90.0f)
            {
                limits.max = Ey;
                limits.min = -limits.max;
            }
            else if (angleRot == 0.0f)
            {
                limits.max = Ex;
                limits.min = -limits.max;
            }
            else if (angleRot == 45.0f)
            {
                limits.max = Mathf.Sqrt(Ex * Ex + Ey * Ey);
                limits.min = -limits.max;
            }
            GetComponent <SliderJoint2D> ().limits = limits;

            GetComponent <SliderJoint2D> ().angle = col.GetComponent <Rigidbody2D> ().rotation;
            Debug.Log("Rotation =" + col.GetComponent <Rigidbody2D> ().rotation + "Angle = " + angleRot + "Limits  =" + limits.max);
        }
    }
    public static int constructor(IntPtr l)
    {
        int result;

        try
        {
            JointTranslationLimits2D jointTranslationLimits2D = default(JointTranslationLimits2D);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, jointTranslationLimits2D);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Beispiel #8
0
    //When it is determined the angle of impact is correct, impale the food on the sword
    public void Impaled()
    {
        //Play sound
        if (foodLetter == 'o')
        {
            audioManager.PlaySoundEffect(audioManager.Clips.onionSound);
        }
        else if (foodLetter == 'm')
        {
            audioManager.PlaySoundEffect(audioManager.Clips.meatSound);
        }
        else
        {
            audioManager.PlaySoundEffect(audioManager.Clips.impaledSounds[UnityEngine.Random.Range(0, audioManager.Clips.impaledSounds.Length)]);
        }

        //Change face
        faceManager.ChangeFace(faceManager.happyFaceSprites[UnityEngine.Random.Range(0, faceManager.happyFaceSprites.Length)], true);

        //Give the player points
        pointManager.IncreasePoints(impalePointValue);

        //Create the joint between this object and the blade, and set the parameters the way I want
        foodSlide = blade.AddComponent <SliderJoint2D>();
        foodSlide.connectedBody      = rb;
        foodSlide.autoConfigureAngle = false;
        //foodSlide.autoConfigureConnectedAnchor = true;
        foodSlide.useLimits  = true;
        foodSlide.breakForce = breakForce;
        foodSlide.angle      = 0;

        JointTranslationLimits2D foodSlideLimits = foodSlide.limits;

        foodSlideLimits.min = jointLimitMin;
        foodSlideLimits.max = jointLimitMax;

        foodSlide.limits = foodSlideLimits;

        //Set bools
        isOffTip  = false;
        isImpaled = true;
    }
Beispiel #9
0
    void SetJoints(Transform wheel, Transform wheelPivot)
    {
        wheel.GetComponent <HingeJoint2D>().connectedBody       = wheelPivot.GetComponent <Rigidbody2D>();
        wheelPivot.GetComponent <SliderJoint2D>().connectedBody = gameObject.GetComponent <Rigidbody2D>();
        wheelPivot.GetComponent <SpringJoint2D>().connectedBody = gameObject.GetComponent <Rigidbody2D>();

        SliderJoint2D sliderJoint = wheelPivot.GetComponent <SliderJoint2D>();

        sliderJoint.enableCollision = true;
        sliderJoint.connectedAnchor = new Vector2(wheelPivot.transform.localPosition.x, wheelPivot.localPosition.y);

        float damper;
        float stiffness;

        if (wheel.GetComponent <Wheel2D>().UseThisSettings)
        {
            damper    = wheel.GetComponent <Wheel2D>().DamperSize;
            stiffness = wheel.GetComponent <Wheel2D>().DamperStiffness;
        }
        else
        {
            damper    = DamperSize;
            stiffness = DamperStiffness;
        }

        sliderJoint.useLimits = true;
        JointTranslationLimits2D limit = new JointTranslationLimits2D();


        limit.min          = -damper;
        limit.max          = damper;
        sliderJoint.limits = limit;

        SpringJoint2D springJoint = wheelPivot.GetComponent <SpringJoint2D>();

        springJoint.enableCollision = true;
        springJoint.connectedAnchor = new Vector2(wheelPivot.transform.localPosition.x, wheelPivot.localPosition.y + (-DamperSize));

        springJoint.frequency = stiffness;
    }
Beispiel #10
0
        public override void OnEnter()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go != null)
            {
                _joint = go.GetComponent <SliderJoint2D>();

                if (_joint != null)
                {
                    _motor  = _joint.motor;
                    _limits = _joint.limits;
                }
            }

            SetProperties();

            if (!everyFrame)
            {
                Finish();
            }
        }
Beispiel #11
0
        void Awake()
        {
            _runnerLength     = GetComponentInChildren <Rigidbody2D>().transform.localScale.x;
            _sliderJoint      = GetComponentInChildren <SliderJoint2D>();
            _hingeJoint       = _sliderJoint.GetComponent <HingeJoint2D>();
            _interactionPoint = GetComponentInChildren <BoxCollider2D>().transform;

            _sliderJoint.useLimits = true;
            _sliderJoint.useMotor  = true;
            _hingeJoint.useLimits  = true;

            var limits = new JointTranslationLimits2D();

            if (IsExtended)
            {
                limits.min = RunnerRight ? 0 : -_runnerLength;
                limits.max = RunnerRight ? _runnerLength : 0;

                _extendedPosition  = _hingeJoint.connectedAnchor.x;
                _collapsedPosition = RunnerRight
                                        ? _hingeJoint.connectedAnchor.x + _runnerLength
                                        : _hingeJoint.connectedAnchor.x - _runnerLength;
                SetInteractionPoint();
            }
            else
            {
                limits.min = RunnerRight ? -_runnerLength : 0;
                limits.max = RunnerRight ? 0 : _runnerLength;

                _collapsedPosition = _hingeJoint.connectedAnchor.x;
                _extendedPosition  = RunnerRight
                                        ? _hingeJoint.connectedAnchor.x - _runnerLength
                                        : _hingeJoint.connectedAnchor.x + _runnerLength;
                SetInteractionPoint();
            }
            _sliderJoint.limits = limits;
            _wasExtended        = !IsExtended;
        }
Beispiel #12
0
    static int get_max(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name max");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index max on a nil value");
            }
        }

        JointTranslationLimits2D obj = (JointTranslationLimits2D)o;

        LuaScriptMgr.Push(L, obj.max);
        return(1);
    }
Beispiel #13
0
    static int set_min(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name min");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index min on a nil value");
            }
        }

        JointTranslationLimits2D obj = (JointTranslationLimits2D)o;

        obj.min = (float)LuaScriptMgr.GetNumber(L, 3);
        LuaScriptMgr.SetValueObject(L, 1, obj);
        return(0);
    }
Beispiel #14
0
 internal void Set(JointTranslationLimits2D l)
 {
     min = l.min;
     max = l.max;
 }
Beispiel #15
0
    void loadJsonJoints(JSONNode jsonJoints)
    {
        int JointCount = 0;

        for (int i = 0, numberOfJoints = jsonJoints.Count; i < numberOfJoints; i++)
        {
            JSONNode jsonJoint = jsonJoints[i];
            int      jointType = jsonJoint["jointType"].AsInt;

            GameObject bodyA = loadedObjects[jsonJoint["bodyA"].AsInt];
            GameObject bodyB = loadedObjects[jsonJoint["bodyB"].AsInt];

            JSONNode localAnchorA     = jsonJoint["localAnchorA"];
            Vector2  anchorA          = new Vector2(localAnchorA[0].AsFloat / RATIO, -localAnchorA[1].AsFloat / RATIO);
            JSONNode localAnchorB     = jsonJoint["localAnchorB"];
            Vector2  anchorB          = new Vector2(localAnchorB[0].AsFloat / RATIO, -localAnchorB[1].AsFloat / RATIO);
            bool     collideConnected = jsonJoint["collideConnected"].AsBool;
            string   userData         = jsonJoint["userData"].Value;

            if (jointType == (int)JointTypes.JOINT_DISTANCE || jointType == (int)JointTypes.JOINT_ROPE)
            {
                DistanceJoint2D joint = bodyA.AddComponent <DistanceJoint2D>();
                joint.connectedBody   = bodyB.GetComponent <Rigidbody2D>();
                joint.anchor          = anchorA;
                joint.connectedAnchor = anchorB;

                // distance joint
                if (jsonJoint["length"] != null)
                {
                    joint.distance        = jsonJoint["length"].AsFloat / RATIO;
                    joint.maxDistanceOnly = true;
                }
                // rope joint
                else if (jsonJoint["maxLength"] != null)
                {
                    joint.distance = jsonJoint["maxLength"].AsFloat / RATIO;
                }

                joint.enableCollision = collideConnected;
                joint.name           += '_';
                joint.name           += userData.Length > 0 ? userData : "joint" + JointCount++;
            }
            else if (jointType == (int)JointTypes.JOINT_REVOLUTE)
            {
                HingeJoint2D joint = bodyA.AddComponent <HingeJoint2D>();
                joint.connectedBody   = bodyB.GetComponent <Rigidbody2D>();
                joint.anchor          = anchorA;
                joint.connectedAnchor = anchorB;
                joint.enableCollision = collideConnected;
                joint.name           += '_';
                joint.name           += userData.Length > 0 ? userData : "joint" + JointCount++;

                // limits are not working properly
                bool  enableLimits       = jsonJoint["enableLimit"].AsBool;
                float referenceAngle     = -jsonJoint["referenceAngle"].AsFloat;
                float angleBetweenBodies = Mathf.Atan2(bodyB.transform.position.y - bodyA.transform.position.y,
                                                       bodyB.transform.position.x - bodyA.transform.position.x) * 180 / Mathf.PI;
                float upperAngle     = -jsonJoint["lowerAngle"].AsFloat;
                float lowerAngle     = -jsonJoint["upperAngle"].AsFloat;
                bool  enableMotor    = jsonJoint["enableMotor"].AsBool;
                float motorSpeed     = -jsonJoint["motorSpeed"].AsFloat;
                float maxMotorTorque = jsonJoint["maxMotorTorque"].AsFloat;

                joint.useLimits = enableLimits;
                JointAngleLimits2D limits = new JointAngleLimits2D();
                limits.max     = angleBetweenBodies + upperAngle;
                limits.min     = angleBetweenBodies + lowerAngle;
                joint.limits   = limits;
                joint.useMotor = enableMotor;
                JointMotor2D motor = new JointMotor2D();
                motor.maxMotorTorque = maxMotorTorque;
                motor.motorSpeed     = motorSpeed;
                joint.motor          = motor;
            }
            else if (jointType == (int)JointTypes.JOINT_WHEEL)
            {
                WheelJoint2D joint = bodyA.AddComponent <WheelJoint2D>();
                joint.connectedBody   = bodyB.GetComponent <Rigidbody2D>();
                joint.anchor          = anchorA;
                joint.connectedAnchor = anchorB;
                joint.enableCollision = collideConnected;
                joint.name           += '_';
                joint.name           += userData.Length > 0 ? userData : "joint" + JointCount++;

                bool     enableMotor    = jsonJoint["enableMotor"].AsBool;
                float    motorSpeed     = -jsonJoint["motorSpeed"].AsFloat;
                float    maxMotorTorque = jsonJoint["maxMotorTorque"].AsFloat;
                float    dampingRatio   = jsonJoint["dampingRatio"].AsFloat;
                float    frequency      = jsonJoint["frequencyHZ"].AsFloat;
                JSONNode localAxisA     = jsonJoint["localAxisA"];
                float    angle          = Mathf.Atan2(-localAxisA[1].AsFloat, localAxisA[0].AsFloat) * 180 / Mathf.PI;

                joint.useMotor = enableMotor;
                JointMotor2D motor = new JointMotor2D();
                motor.maxMotorTorque = maxMotorTorque;
                motor.motorSpeed     = motorSpeed;
                joint.motor          = motor;

                JointSuspension2D suspension = new JointSuspension2D();
                suspension.dampingRatio = dampingRatio;
                suspension.frequency    = frequency;
                suspension.angle        = angle;
                joint.suspension        = suspension;
            }
            else if (jointType == (int)JointTypes.JOINT_PRISMATIC)
            {
                SliderJoint2D joint = bodyA.AddComponent <SliderJoint2D>();
                joint.connectedBody   = bodyB.GetComponent <Rigidbody2D>();
                joint.anchor          = anchorA;
                joint.connectedAnchor = anchorB;
                joint.enableCollision = collideConnected;
                joint.name           += '_';
                joint.name           += userData.Length > 0 ? userData : "joint" + JointCount++;

                bool     enableLimits     = jsonJoint["enableLimit"].AsBool;
                float    referenceAngle   = -jsonJoint["referenceAngle"].AsFloat;
                float    upperTranslation = jsonJoint["upperTranslation"].AsFloat / RATIO;
                float    lowerTranslation = jsonJoint["lowerTranslation"].AsFloat / RATIO;
                bool     enableMotor      = jsonJoint["enableMotor"].AsBool;
                float    motorSpeed       = -jsonJoint["motorSpeed"].AsFloat;
                float    maxMotorTorque   = jsonJoint["maxMotorTorque"].AsFloat;
                JSONNode localAxisA       = jsonJoint["localAxisA"];
                float    angle            = Mathf.Atan2(-localAxisA[1].AsFloat, localAxisA[0].AsFloat) * 180 / Mathf.PI;

                joint.useLimits = enableLimits;
                JointTranslationLimits2D limits = new JointTranslationLimits2D();
                limits.max     = upperTranslation;
                limits.min     = lowerTranslation;
                joint.limits   = limits;
                joint.useMotor = enableMotor;
                JointMotor2D motor = new JointMotor2D();
                motor.maxMotorTorque = maxMotorTorque;
                motor.motorSpeed     = motorSpeed;
                joint.motor          = motor;
                joint.angle          = angle;
            }
        }
    }