Esempio n. 1
0
        public void AttachToCat(StackableCat previous)
        {
            _hinge           = previous.gameObject.AddComponent <HingeJoint2D>();
            _hinge.useLimits = true;

            var rotationOffset = -previous.transform.eulerAngles.z;
            var limits         = new JointAngleLimits2D
            {
                min = (-135f + rotationOffset + 360f) % 360f,
                max = (-45f + rotationOffset + 360f) % 360f
            };

            _hinge.limits        = limits;
            _hinge.connectedBody = _rigidBody;
            var motor = new JointMotor2D
            {
                motorSpeed     = 10,
                maxMotorTorque = 10000
            };

            _hinge.motor    = motor;
            _hinge.useMotor = true;

            _distance = previous.gameObject.AddComponent <DistanceJoint2D>();
            _distance.autoConfigureDistance = false;
            _distance.distance      = 2.5f;
            _distance.connectedBody = _rigidBody;

            _rigidBody.bodyType  = RigidbodyType2D.Dynamic;
            _rigidBody.simulated = true;
        }
Esempio n. 2
0
    void Awake()
    {
        gameStop         = false;
        _tr              = transform;
        whenKick_State_1 = scr.bonObjMan.whenKick_State_1_Norm;
        enSprTr          = enSpr.transform;

        kickSpeed = scr.pMov.kickSpeed0;

        if (_enType != OpponentType.Goalkeeper)
        {
            _enType      = scr.buf.oppType;
            enSpr.sprite = scr.buf.enSpr;
            maxSpeed     = scr.pMov.maxSpeed0 * scr.buf.enSkillSpeed / 100f;
            jumpForce    = scr.pMov.jumpForce0 * scr.buf.enSkillJump / 100f;
            kickTorque   = scr.pMov.kickTorque0 * scr.buf.enSkillKick / 100f;
        }
        else
        {
            enSpr.sprite = scr.buf.enSpr_1;
            maxSpeed     = scr.pMov.maxSpeed0 * scr.buf.enSkillSpeed_1 / 100f;
            jumpForce    = scr.pMov.jumpForce0 * scr.buf.enSkillJump_1 / 100f;
            kickTorque   = scr.pMov.kickTorque0 * scr.buf.enSkillKick_1 / 100f;
        }

        SKJ_Upgrades();

        jumpForceDef = jumpForce;
        JointAngleLimits2D limits = legHJ.limits;
        JointMotor2D       motor  = legHJ.motor;

        legHJ.limits         = limits;
        motor.maxMotorTorque = 0;
        legHJ.motor          = motor;
    }
Esempio n. 3
0
    void Awake()
    {
        rb              = GetComponent <Rigidbody2D>();
        myRagdoll       = GetComponentInParent <RagdollManager>();
        footStartXRight = RightFoot.transform.localPosition.x;
        footStartXLeft  = LeftFoot.transform.localPosition.x;
        rightLegLimits  = RightLeg.limits;
        leftLegLimits   = LeftLeg.limits;

        rightArmLimits = RightArm.limits;
        leftArmLimits  = LeftArm.limits;

        //Player Specific Movement added by Kate
        if (transform.parent.CompareTag("PlayerOne"))
        {
            playerInt = 1;
        }
        else if (transform.parent.CompareTag("PlayerTwo"))
        {
            playerInt = 2;
        }

        if (playerInt < 1)
        {
            throw new SystemException("Player Missing Correct Tag: " + transform.name);
        }

        //Gun Control added by Kate
        gunLocation = gunLocationRight.transform;
    }
Esempio n. 4
0
    void Awake()
    {
        rb   = GetComponent <Rigidbody2D>();
        foot = GetComponentInChildren <HingeJoint2D>();

        t            = GetComponent <Transform>();
        initialPos   = t.position;
        initialScale = t.localScale;

        m = foot.motor;
        m.maxMotorTorque = kickMaxMotorForce;

        // Change the side of the foot, depending on the direction the player is facing
        JointAngleLimits2D limits = foot.limits;

        if (facing == Direction.Right)
        {
            limits.min  = -15;
            limits.max  = 105;
            foot.limits = limits;
        }
        else
        {
            limits.min  = 195;
            limits.max  = 75;
            foot.limits = limits;
        }
    }
Esempio n. 5
0
    // слипание клеток
    public void Link(Cell cell)
    {
        if (links.ContainsKey(cell))
        {
            return;
        }
        if (links.Keys.Count > 5)
        {
            return;
        }
        if (cell.links.Keys.Count > 5)
        {
            return;
        }
        HingeJoint2D joint = gameObject.AddComponent <HingeJoint2D>();

        joint.connectedBody = cell.gameObject.GetComponent <Rigidbody2D>();
        joint.useLimits     = true;
        JointAngleLimits2D limits = new JointAngleLimits2D {
            min = -15, max = 15
        };

        joint.limits      = limits;
        joint.breakForce  = 20f;
        joint.breakTorque = 20f;
        links.Add(cell, joint);
        cell.links.Add(this, joint);
    }
Esempio n. 6
0
    void AttachToNewPiece()
    {
        GameObject   prevPiece = pieces[1];
        GameObject   newPiece  = pieces[0];
        HingeJoint2D joint     = prevPiece.AddComponent <HingeJoint2D>();

        joint.connectedBody = newPiece.GetComponent <Rigidbody2D>();
        JointAngleLimits2D limits = joint.limits;

        limits.min      = 0;
        limits.max      = 90;
        joint.limits    = limits;
        joint.useLimits = true;

        DistanceJoint2D distance = prevPiece.AddComponent <DistanceJoint2D>();

        distance.connectedBody   = newPiece.GetComponent <Rigidbody2D>();
        distance.maxDistanceOnly = true;

        FixedJoint2D fixedJoint = newPiece.AddComponent <FixedJoint2D>();

        fixedJoint.connectedBody = ropeBase;

        ropeBase.transform.Translate(0, -0.5f, 0);

        Invoke("AddPiece", 0.1f);
    }
Esempio n. 7
0
    void CreateAllLinks(Rigidbody2D[] parents)
    {
        List <Rigidbody2D> newParents = new List <Rigidbody2D>();

        Rigidbody2D rigidbodyTemp;

        _jointLimit     = new JointAngleLimits2D();
        _jointLimit.min = -_angleLimit * 0.5f;
        _jointLimit.max = _angleLimit * 0.5f;

        for (int i = 0; i < parents.Length; i++)
        {
            for (int j = 0; j < parents[i].transform.childCount; j++)
            {
                if (!IsExclude(parents[i].transform.GetChild(j)))
                {
                    rigidbodyTemp = parents[i].transform.GetChild(j).gameObject.AddComponent <Rigidbody2D>();
                    if (parents[i].transform.GetChild(j).childCount > 0)
                    {
                        newParents.Add(rigidbodyTemp);
                    }
                    _links.Add(new Link(rigidbodyTemp, parents[i], _jointLimit));
                }
            }
        }
        if (newParents.Count > 0)
        {
            CreateAllLinks(newParents.ToArray());
        }
        newParents.Clear();
    }
Esempio n. 8
0
    public static void increaseLength()
    {
        leadermovement.ForwardForce  += 0.6f;
        leadermovement.RotationSpeed += 7;
        applyDiminishingDrag();
        List <GameObject> templist = convoylist1.getVehicles();
        int        size            = convoylist1.getVehicles().Count;
        Vector2    pos             = templist[size - 1].transform.position - templist[size - 1].transform.up;
        Quaternion rot             = templist[size - 1].transform.rotation;
        //pos = pos-new Vector3(0,-1,0);
        GameObject tempobj = Instantiate(Resources.Load("prefabs/bodySection"), pos, rot) as GameObject;        //Instantiate(Resources.Load("PrefabName"), position, rotation)

        tempobj.tag = "body";
        HingeJoint2D hj = templist[size - 1].AddComponent <HingeJoint2D>() as HingeJoint2D;

        hj.anchor    = new Vector2(0, -1);
        hj.useLimits = true;
        JointAngleLimits2D lims = hj.limits;

        lims.min  = -45;
        lims.max  = 45;
        hj.limits = lims;
        templist[size - 1].GetComponent <HingeJoint2D>().connectedBody = tempobj.GetComponent <Rigidbody2D>();
        //tempobj.transform.localScale = new Vector3(1,1,1);
        //OTAnimatingSprite otscript = tempobj.GetComponent<OTAnimatingSprite>();
        //otscript.size.X = 1;
        //otscript.size.Y = 1;
        convoylist1.getVehicles().Add(tempobj);
    }
Esempio n. 9
0
        public static void ReadHingeJoint2D(this BinaryReader reader, HingeJoint2D joint)
        {
            byte flags = reader.ReadByte();

            joint.enabled         = (flags & 0x01) > 0;
            joint.anchor          = reader.ReadVector2();
            joint.connectedAnchor = reader.ReadVector2() + (Vector2)joint.transform.position;

            if ((flags & 0x02) > 0)
            {
                joint.useMotor = true;
                JointMotor2D motor = joint.motor;
                motor.motorSpeed     = reader.ReadSingle();
                motor.maxMotorTorque = reader.ReadSingle();
                joint.motor          = motor;
            }
            else
            {
                joint.useMotor = false;
            }

            if ((flags & 0x04) > 0)
            {
                joint.useLimits = true;
                JointAngleLimits2D limits = joint.limits;
                limits.min   = reader.ReadSingle();
                limits.max   = reader.ReadSingle();
                joint.limits = limits;
            }
            else
            {
                joint.useLimits = false;
            }
        }
Esempio n. 10
0
    void Start()
    {
        _activeLimits = new JointAngleLimits2D {
            min = Flip ? 90 : -90, max = 0
        };
        _passiveLimits = new JointAngleLimits2D {
            min = 0, max = 0
        };

        _joint = GetComponent <HingeJoint2D>();
        if (IsActive)
        {
            _joint.limits = _activeLimits;

            _motorHit                = new JointMotor2D();
            _motorHit.motorSpeed     = Flip ? MotorSpeed : -MotorSpeed;
            _motorHit.maxMotorTorque = MaxMotorTorque;

            _motorIdle                = new JointMotor2D();
            _motorIdle.motorSpeed     = Flip ? -MotorSpeed : MotorSpeed;;
            _motorIdle.maxMotorTorque = MaxMotorTorque;
        }
        else
        {
            _joint.limits = _passiveLimits;

            _motorHit                = new JointMotor2D();
            _motorHit.motorSpeed     = MotorSpeed;
            _motorHit.maxMotorTorque = MaxMotorTorque;

            _motorIdle                = new JointMotor2D();
            _motorIdle.motorSpeed     = -MotorSpeed;
            _motorIdle.maxMotorTorque = MaxMotorTorque;
        }
    }
Esempio n. 11
0
    // Update is called once per frame
    void Update()
    {
        if (!settedMinMax)
        {
            settedMinMax = true;
            JointAngleLimits2D newLimits = hinge.limits;
            newLimits.min = minMax.x;
            newLimits.max = minMax.y;
            hinge.limits  = newLimits;
        }

        if (hinge.jointAngle >= hinge.limits.max)
        {
            JointMotor2D newMotor = hinge.motor;
            newMotor.motorSpeed = -Mathf.Abs(newMotor.motorSpeed);
            hinge.motor         = newMotor;

            JointAngleLimits2D newLimits = hinge.limits;
            newLimits.min = -Random.Range(0f, 60f);
            hinge.limits  = newLimits;
        }
        else if (hinge.jointAngle <= hinge.limits.min)
        {
            JointMotor2D newMotor = hinge.motor;
            newMotor.motorSpeed = Mathf.Abs(newMotor.motorSpeed);
            hinge.motor         = newMotor;

            JointAngleLimits2D newLimits = hinge.limits;
            newLimits.max = Random.Range(0f, 60f);
            hinge.limits  = newLimits;
        }
    }
Esempio n. 12
0
    // Update is called once per frame
    private void FixedUpdate()
    {
        Rigidbody2D connectedBody = hj2D.connectedBody;

        //필요 없으나 에디터 뷰에서 정확한 움직임 확인 가능
        if (degMax != hj2D.limits.max)
        {
            JointAngleLimits2D limit = hj2D.limits;
            limit.max   = degMax;
            limit.min   = -degMax;
            hj2D.limits = limit;
        }

        if (Mathf.Abs(connectedBody.rotation) >= degMax)
        {
            dir = -(int)Mathf.Sign(connectedBody.rotation);
            hj2D.connectedBody.rotation = degMax * (-dir);
        }


        JointMotor2D motor = hj2D.motor;

        float percentOfSwing = lean * (-Mathf.Pow(connectedBody.rotation / degMax, 2) + 1.1f);
        float spd            = dir * motorSpeed * percentOfSwing;


        motor.motorSpeed = spd;
        hj2D.motor       = motor;
    }
Esempio n. 13
0
    HingeJoint2D CreateJoint(BoneBridgeSnapToSocket socket, float lowerAngle, float upperAngle, float anchorOffset)
    {
        if (GetComponent <Rigidbody2D> ())
        {
            boneJoint = gameObject.AddComponent <HingeJoint2D> ();
        }
        else
        {
            boneJoint        = transform.parent.gameObject.AddComponent <HingeJoint2D> ();
            boneJoint.anchor = new Vector2(anchorOffset, boneJoint.anchor.y);
        }

        socket.GetComponent <BoneBridgeJoint> ().boneJoint = boneJoint;

        Rigidbody2D rigBody = socket.transform.parent.GetComponent <Rigidbody2D> ();

        rigBody.velocity        = Vector2.zero;
        boneJoint.breakForce    = jointBreakForce;
        boneJoint.connectedBody = rigBody;

        JointAngleLimits2D limits = boneJoint.limits;

        limits.min          = lowerAngle;
        limits.max          = upperAngle;
        boneJoint.limits    = limits;
        boneJoint.useLimits = true;
        return(boneJoint);
    }
Esempio n. 14
0
    public void EnableLock(bool enable)
    {
        if (!enabled)
        {
            angleLocker.enabled = false;
            return;
        }
        JointAngleLimits2D limits = angleLocker.limits;

        switch (difficulty)
        {
        case Difficulty.Easy:
            angleLocker.enabled = true;
            limits.min          = -easyLockAngle;
            limits.max          = easyLockAngle;
            break;

        case Difficulty.Medium:
            angleLocker.enabled = true;
            limits.min          = -mediumLockAngle;
            limits.max          = mediumLockAngle;
            break;

        case Difficulty.Hard:
            angleLocker.enabled = false;
            break;
        }
        angleLocker.limits = limits;
    }
    // Update is called once per frame
    void Update() //I'm using Update rather than FixedUpdate because when I tried FixedUpdate, GetKeyDown was calling the interact key twice rather than once. And at that point what the f**k is the point of using GetKeyDown?
    {
        if (Input.GetKeyDown(interact))
        {
            Debug.Log("You pressed E");

            if (isOpenable == true && isOpen == false)                                              //This opens the door
            {
                HingeJoint2D hinge = gameObject.GetComponent(typeof(HingeJoint2D)) as HingeJoint2D; //locally initializing our 2D Hinge Point
                rb.constraints = RigidbodyConstraints2D.None;                                       //Removing the rotation constraints placed on the door originally
                hinge.enabled  = true;                                                              //Enabling our HingeJoint2D
                isOpen         = true;                                                              //Setting this bool to true tells us this door is open.
                Door.GetComponent <BoxCollider2D>().enabled = false;
            }
            else if (isOpenable == true && isOpen == true)
            {
                HingeJoint2D hinge = gameObject.GetComponent(typeof(HingeJoint2D)) as HingeJoint2D;
                JointMotor2D motor = hinge.motor;
                motor.motorSpeed = -motor.motorSpeed;
                hinge.motor      = motor;
                JointAngleLimits2D limits = this.gameObject.GetComponent <HingeJoint2D>().limits;
                limits.min = limits.min + 90;
                limits.max = limits.max;
                this.gameObject.GetComponent <HingeJoint2D>().limits = limits;

                //This commented shit is what I want to do once the door is not moving and in the closed position.
                //isOpen = false;
                //Door.GetComponent<BoxCollider2D>().enabled = true;
                //rb.constraints = RigidbodyConstraints2D.FreezeAll;
                //JointAngleLimits2D limits = this.gameObject.GetComponent<HingeJoint2D>().limits;
                //limits.min = limits.min - 90;
                //this.gameObject.GetComponent<HingeJoint2D>().limits = limits;
            }
        }
    }
Esempio n. 16
0
        //\this being here will save GC allocs


        // Use this for initialization
        void Start()
        {
            _joint = (HingeJoint2D)gameObject.GetComponent("HingeJoint2D");
            _joint.connectedAnchor = transform.TransformPoint(_joint.anchor);
            _default_limits        = _joint.limits;
            _stop_limits.min       = 0f;
            _stop_limits.max       = 0f;
        }
Esempio n. 17
0
    public void Start()
    {
        JointAngleLimits2D limits = joint.limits;

        limits.min   = joint.limits.max;
        limits.max   = joint.limits.min;
        joint.limits = limits;
    }
Esempio n. 18
0
    // Set min and max angle hinge can turn to
    public void setLimits(float min, float max)
    {
        JointAngleLimits2D limits = hinge.limits;

        limits.max   = max;
        limits.min   = min;
        hinge.limits = limits;
    }
Esempio n. 19
0
    static int _CreateJointAngleLimits2D(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 0);
        JointAngleLimits2D obj = new JointAngleLimits2D();

        LuaScriptMgr.PushValue(L, obj);
        return(1);
    }
Esempio n. 20
0
        public JointAngleLimits2D ToJointAngleLimits2D()
        {
            JointAngleLimits2D limits = new JointAngleLimits2D();

            limits.min = min;
            limits.max = max;
            return(limits);
        }
Esempio n. 21
0
    /// <summary>
    /// 同组的成员销毁
    /// </summary>
    public void GroupMemberDestroy()
    {
        JointAngleLimits2D jointAngleLimits2D = new JointAngleLimits2D {
            min = -180, max = 180
        };

        hingeJoint2D.limits = jointAngleLimits2D; //重新设置一下旋转角度
    }
Esempio n. 22
0
 private void Awake()
 {
     hingeJoint2D    = transform.Find("Hinge").GetComponent <HingeJoint2D>();
     openDoorLimits  = hingeJoint2D.limits;
     closeDoorLimits = new JointAngleLimits2D {
         min = 0f, max = 0f
     };
     CloseDoor();
 }
Esempio n. 23
0
    void useLimit()
    {
        joint2D.useLimits = true;
        JointAngleLimits2D limit = joint2D.limits;

        limit.max      = joint2D.jointAngle;
        limit.min      = joint2D.jointAngle;
        joint2D.limits = limit;
    }
Esempio n. 24
0
        private void SetHingeLimits()
        {
            var   limits     = new JointAngleLimits2D();
            float angleLimit = 5 + (175 * (Mathf.Abs(_hingeJoint.transform.localPosition.x) / _runnerLength));

            limits.max         = -angleLimit;
            limits.min         = angleLimit;
            _hingeJoint.limits = limits;
        }
Esempio n. 25
0
        public new void OnSceneGUI()
        {
            HingeJoint2D hingeJoint2D = (HingeJoint2D)base.target;

            if (hingeJoint2D.enabled)
            {
                this.m_AngularLimitHandle.xMotion = ((!hingeJoint2D.useLimits) ? ConfigurableJointMotion.Free : ConfigurableJointMotion.Limited);
                JointAngleLimits2D limits = hingeJoint2D.limits;
                this.m_AngularLimitHandle.xMin = limits.min;
                this.m_AngularLimitHandle.xMax = limits.max;
                bool flag = EditMode.editMode == EditMode.SceneViewEditMode.JointAngularLimits && EditMode.IsOwner(this);
                if (flag)
                {
                    this.m_AngularLimitHandle.angleHandleDrawFunction = null;
                }
                else
                {
                    this.m_AngularLimitHandle.angleHandleDrawFunction = new Handles.CapFunction(this.NonEditableHandleDrawFunction);
                }
                Rigidbody2D rigidbody2D  = hingeJoint2D.attachedRigidbody;
                Vector3     point        = Vector3.right;
                Vector2     v            = hingeJoint2D.anchor;
                Rigidbody2D rigidbody2D2 = hingeJoint2D.connectedBody;
                Quaternion  rhs          = HingeJoint2DEditor.s_RightHandedHandleOrientationOffset;
                if (rigidbody2D.bodyType != RigidbodyType2D.Dynamic && hingeJoint2D.connectedBody != null && hingeJoint2D.connectedBody.bodyType == RigidbodyType2D.Dynamic)
                {
                    rigidbody2D  = hingeJoint2D.connectedBody;
                    point        = Vector3.left;
                    v            = hingeJoint2D.connectedAnchor;
                    rigidbody2D2 = hingeJoint2D.attachedRigidbody;
                    rhs          = HingeJoint2DEditor.s_LeftHandedHandleOrientationOffset;
                }
                Vector3    vector = Joint2DEditor.TransformPoint(rigidbody2D.transform, v);
                Quaternion q      = ((!(rigidbody2D2 == null)) ? Quaternion.LookRotation(Vector3.forward, rigidbody2D2.transform.rotation * Vector3.up) : Quaternion.identity) * rhs;
                Vector3    point2 = vector + Quaternion.LookRotation(Vector3.forward, rigidbody2D.transform.rotation * Vector3.up) * point;
                Matrix4x4  matrix = Matrix4x4.TRS(vector, q, Vector3.one);
                EditorGUI.BeginChangeCheck();
                using (new Handles.DrawingScope(HingeJoint2DEditor.Styles.handleColor, matrix))
                {
                    float num = HandleUtility.GetHandleSize(Vector3.zero) * HingeJoint2DEditor.Styles.handleRadius;
                    this.m_AngularLimitHandle.radius = num;
                    Handles.DrawLine(Vector3.zero, matrix.inverse.MultiplyPoint3x4(point2).normalized *num);
                    this.m_AngularLimitHandle.DrawHandle();
                }
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(hingeJoint2D, HingeJoint2DEditor.Styles.editAngularLimitsUndoMessage);
                    limits              = hingeJoint2D.limits;
                    limits.min          = this.m_AngularLimitHandle.xMin;
                    limits.max          = this.m_AngularLimitHandle.xMax;
                    hingeJoint2D.limits = limits;
                    rigidbody2D.WakeUp();
                }
                base.OnSceneGUI();
            }
        }
Esempio n. 26
0
    void InitialisePlayerTank()
    {
        tankRigidBody = GameObject.Find("NavyTankBase").GetComponent <Rigidbody2D>();
        barrelHinge   = gameObject.AddComponent <HingeJoint2D>();

        JointAngleLimits2D jointLimits = barrelHinge.limits;

        barrelHinge.connectedBody = tankRigidBody;
        barrelHinge.autoConfigureConnectedAnchor = true;
    }
    protected void SetJointLimit(float upper, float lower)
    {
        JointAngleLimits2D temp = new JointAngleLimits2D
        {
            max = upper,
            min = lower
        };

        _bodyJoint.limits = temp;
    }
Esempio n. 28
0
    protected override void Awake()
    {
        base.Awake();
        hj = GetComponent <HingeJoint2D>();
        rb = GetComponent <Rigidbody2D>();

        JointAngleLimits2D ja = new JointAngleLimits2D();

        ja.max    = maxAngle; ja.min = minAngle;
        hj.limits = ja;
    }
Esempio n. 29
0
    void Start()
    {
        hingeJoint1 = gameObject.GetComponent <HingeJoint2D>();
        jointMotor  = hingeJoint1.motor;
        JointAngleLimits2D limits = hingeJoint1.limits;

        limits.min            = -30;
        limits.max            = 30;
        hingeJoint1.limits    = limits;
        hingeJoint1.useLimits = true;
    }
Esempio n. 30
0
    // Use this for initialization
    void Start()
    {
        minMax = new Vector2(hinge.limits.min, hinge.limits.max);
        float rand = Random.Range(hinge.limits.min, hinge.limits.max);

        JointAngleLimits2D newLimits = hinge.limits;

        newLimits.min = rand;
        newLimits.max = rand;
        hinge.limits  = newLimits;
    }