public bool Equip(Weapon weapon, Vector3 weaponToHandleOffset)
        {
            if (EquippingDisabled)
            {
                return(false);
            }

            if (currentWeapon != null)
            {
                return(false);
            }

            SetIgnoreCollisions(weapon, true);

            // Sets the desired position and rotation for the weapon
            // which will be kept by the FixedJoint2D (added at LateUpdate).
            weapon.transform.position = hand.transform.position;
            weapon.transform.rotation = hand.transform.rotation;

            // If this weapon was previously equipped by an enemy then Y scale is negative. We need to fix it here.
            weapon.transform.localScale = new Vector3(weapon.transform.localScale.x, Mathf.Abs(weapon.transform.localScale.y), weapon.transform.localScale.z);

            currentWeapon = weapon;
            currentWeaponToHandleOffset = weaponToHandleOffset;

            lateUpdateAction = () =>
            {
                // Finishes equipping. Needed to be done at LateUpdate to solve a bug with Joint2D.
                // Creates the joint to grab the current weapon.
                joint = CreateHandToWeaponJoint();
                weaponEquippedEvent?.Invoke();
            };

            return(true);
        }
Example #2
0
 private void OnBreak(Joint2D arg0)
 {
     if (arg0 == ball1.GetComponent <Joint2D> () || arg0 == ball2.GetComponent <Joint2D> ())
     {
         this.gameObject.SetActive(false);
     }
 }
Example #3
0
 public void RecalculateJoints()
 {
     if (body2D)
     {
         joints = Joint2D.GetJointsConnected(body2D);
     }
 }
 private void OnJointBreak2D(Joint2D joint)
 {
     GameManager.instance.PlacedPiece();
     joint.connectedBody.GetComponent <Collider2D>().enabled = false;
     joint.connectedBody.AddForce(Vector2.up * 10f, ForceMode2D.Force);
     joint.connectedBody = null;
 }
Example #5
0
 void OnJointBreak2D(Joint2D brokenJoint)
 {
     rb2d.freezeRotation = true;
     inUse = false;
     player.SetHoldingBox(false);
     //rb2d.velocity = new Vector2(0.0f, rb2d.velocity.y);
 }
Example #6
0
    public void Start()
    {
        joints = Joint2D.GetJoints(gameObject);

        Max2D.Check();
        material = new Material(Max2D.lineMaterial);
    }
 private void OnJointBreak2D(Joint2D joint)
 {
     if (GenClass != null)
     {
         GenClass.OnJointBreak2D(joint);
     }
 }
Example #8
0
 private void OnJointBreak2D(Joint2D joint)
 {
     if (joint == attachmentPointJoint)
     {
         DetachHead();
     }
 }
 private void OnJointBreak2D(Joint2D joint)
 {
     if (state.localPlayerControl.Value)
     {
         signalBus.Fire <PlayerKilledSignal>();
     }
 }
Example #10
0
        public void DestroyLimb(bool destroyJoint)
        {
            if (IsDestroyed)
            {
                return;
            }

            if (destroyJoint && jointToDestroy != null)
            {
                Destroy(jointToDestroy);
                jointToDestroy = null;

                transform.SetParent(null, true);
            }

            var componentsToDisable = GetComponents <IDisableableLimbComponent>();

            foreach (var c in componentsToDisable)
            {
                c.DisableLimbComponent();
            }

            IsDestroyed = true;

            limbDestroyedEvent?.Invoke();

            Invoke(nameof(CreateDestroyedParticles), Random.Range(1.0f, 4.0f));

            AudioManager.Instance.CreateTemporaryAudioSourceAt("LimbDestroyed", transform.position);
        }
 void OnJointBreak2D(Joint2D brokenJoint)
 {
     if (onJointBreak2D != null)
     {
         onJointBreak2D(brokenJoint);
     }
 }
Example #12
0
 // Start is called before the first frame update
 void Start()
 {
     rigid         = GetComponent <Rigidbody2D>();
     joint         = GetComponent <Joint2D>();
     transform     = GetComponent <Transform>();
     joint.enabled = false;
 }
 public void Grab(Joint2D joint)
 {
     if (rb != null)
     {
         joint.connectedBody = rb;
     }
 }
Example #14
0
    // Detaches from currently attached players.
    public void Detach()
    {
        // Remove associations to other BindEngine instances
        if (boundObjects.Any())
        {
            for (int i = boundObjects.Count - 1; i >= 0; i--)
            {
                BindEngine other = boundObjects[i];
                Debug.Log(string.Format("BindEngine: unbinding objects {0} and {1}", gameObject.name, other.gameObject.name));
                other.boundObjects.Remove(this);
                boundObjects.RemoveAt(i);
            }
        }

        // Remove all bind displays and joints. This assumes that bindJoints and bindDisplays always
        // have the same lengths, since no other code explicitly removes them even if an object in
        // the list is destroyed.
        for (int i = bindJoints.Count - 1; i >= 0; i--)
        {
            Joint2D joint = bindJoints[i];
            if (joint != null)
            {
                Destroy(joint);
            }
            bindJoints.RemoveAt(i);

            GameObject bd = bindDisplays[i];
            if (bd != null)
            {
                Destroy(bd);
            }
            bindDisplays.RemoveAt(i);
        }
    }
Example #15
0
        public static GearJoint CreateGearJoint(World world, Body bodyA, Body bodyB, Joint2D jointA, Joint2D jointB, FP ratio)
        {
            GearJoint gearJoint = new GearJoint(bodyA, bodyB, jointA, jointB, ratio);

            world.AddJoint(gearJoint);
            return(gearJoint);
        }
    static public void LinearSliceJoints(Pair2D slice)
    {
        foreach (Joint2D joint in Joint2D.GetJointsConnected())
        {
            Vector2 localPosA = joint.anchoredJoint2D.connectedAnchor;
            Vector2 worldPosA = joint.anchoredJoint2D.connectedBody.transform.TransformPoint(localPosA);
            Vector2 localPosB = joint.anchoredJoint2D.anchor;
            Vector2 worldPosB = joint.anchoredJoint2D.transform.TransformPoint(localPosB);

            switch (joint.jointType)
            {
            case Joint2D.Type.HingeJoint2D:
                worldPosA = joint.anchoredJoint2D.connectedBody.transform.position;
                break;

            default:
                break;
            }

            Pair2D jointLine = new Pair2D(worldPosA, worldPosB);

            if (Math2D.LineIntersectLine(slice, jointLine))
            {
                UnityEngine.Object.Destroy(joint.anchoredJoint2D);
            }
        }
    }
Example #17
0
 void OnJointBreak2D(Joint2D broken)
 {
     if (broken == joint)
     {
         releaseFromHolder();
     }
 }
Example #18
0
 private void OnJointBreak2D(Joint2D joint)
 {
     if (OnJointBreak2DAction != null)
     {
         OnJointBreak2DAction(this, joint);
     }
 }
Example #19
0
    void OnJointBreak2D(Joint2D brokenJoint)
    {
        var center = (SpriteUtils.GetWolrdPositions(brokenJoint.attachedRigidbody.GetComponent <SpriteRenderer>()).Center + SpriteUtils.GetWolrdPositions(spriteRenderer).Center) / 2;
        var ps     = particleSystemContainer.NextAndPlay();

        ps.transform.position = new Vector3(center.x, center.y, Z_POSSITION);
    }
    void OnJointBreak2D(Joint2D brokenJoint)
    {
        //Instantitate the blood gameobject at the broken joint
        GameObject bloodGO = Instantiate(blood, brokenJoint.transform.position, transform.rotation) as GameObject;

        bloodGO.transform.parent = transform.parent.FindChild("Body");

        //Add lost mass to the connected rigidbody to prevent flying
        brokenJoint.connectedBody.GetComponent <Rigidbody2D>().mass += GetComponent <Rigidbody2D>().mass;

        //If this is the head, stop moving (because you're dead)
        if (isHead)
        {
            //Add everything to the dead layer
            transform.parent.gameObject.layer = LayerMask.NameToLayer("Dead");
            foreach (Transform t in transform.parent.GetComponentsInChildren <Transform>())
            {
                if (t.GetComponent <LimbLoss>())
                {
                    t.gameObject.layer = LayerMask.NameToLayer("Dead");
                    t.gameObject.AddComponent <DeadBehaviour>();
                }
            }
            //Tell the manager that you're dead
            manager.AddDeath(transform.parent);

            //Die
            Destroy(transform.parent.GetComponent <CharacterMovement>());
        }
        else
        {
            gameObject.layer = LayerMask.NameToLayer("Dead");
            manager.AddInjury(transform.parent);
        }
    }
Example #21
0
    private void ComplexSliceJoints(List <Vector2D> slice)
    {
        foreach (Joint2D joint in Joint2D.GetJointsConnected())
        {
            Vector2 localPosA = joint.anchoredJoint2D.connectedAnchor;
            Vector2 worldPosA = joint.anchoredJoint2D.connectedBody.transform.TransformPoint(localPosA);
            Vector2 localPosB = joint.anchoredJoint2D.anchor;
            Vector2 worldPosB = joint.anchoredJoint2D.transform.TransformPoint(localPosB);

            switch (joint.jointType)
            {
            case Joint2D.Type.HingeJoint2D:
                worldPosA = joint.anchoredJoint2D.connectedBody.transform.position;
                break;

            default:
                break;
            }

            Pair2D jointLine = new Pair2D(worldPosA, worldPosB);

            foreach (Pair2D pair in Pair2D.GetList(slice, false))
            {
                if (Math2D.LineIntersectLine(pair, jointLine))
                {
                    Destroy(joint.anchoredJoint2D);
                }
            }
        }
    }
 public static Joint2DSettingsBase GetOrCreate(Joint2D joint2D)
 {
     if (!joint2D)
     {
         throw new ArgumentException("The joint is null!?");
     }
     if (joint2D is HingeJoint2D)
     {
         return(GetOrCreate <HingeJoint2DSettings>(joint2D));
     }
     if (joint2D is DistanceJoint2D)
     {
         return(GetOrCreate <DistanceJoint2DSettings>(joint2D));
     }
     if (joint2D is SliderJoint2D)
     {
         return(GetOrCreate <SliderJoint2DSettings>(joint2D));
     }
     if (joint2D is WheelJoint2D)
     {
         return(GetOrCreate <WheelJoint2DSettings>(joint2D));
     }
     if (joint2D is SpringJoint2D)
     {
         return(GetOrCreate <SpringJoint2DSettings>(joint2D));
     }
     throw new ArgumentException("There are no editors defined for the joint2D: " + joint2D.GetType());
 }
Example #23
0
    /// <summary>
    /// Grabs the specified object as if grabbing a rope.
    /// </summary>
    /// <param name="objectToGrab">The Rigidbody to which the physics Joint will be attached.</param>
    /// <param name="whereToGrabIt">The global location where the rope should be grabbed. Can be null</param>
    public void GrabRope(Rigidbody2D objectToGrab, Vector2?whereToGrabIt)
    {
        // If we were grabbing something before, stop grabbing it.
        if (isGrabbingObject)
        {
            Ungrab();
        }

        // Create a HingeJoint which we will use to hold on to the object.
        var hinge = gameObject.AddComponent <HingeJoint2D> ();

        // Connect the hinge to /objectToGrab/ at location /whereToGrabIt/ (or the default location if /whereToGrabIt/ is null)
        hinge.connectedBody = objectToGrab;

        if (whereToGrabIt.HasValue)
        {
            hinge.autoConfigureConnectedAnchor = false;
            hinge.connectedAnchor = whereToGrabIt.Value - (Vector2)objectToGrab.transform.position;
        }
        else
        {
            hinge.autoConfigureConnectedAnchor = true;
        }

        // Place the hinge at the offset of our /grabRopeLocation/
        hinge.anchor = grabRopeLocation.position - transform.position;


        // Remember that we're grabbing an object and keep a reference to the hinge
        isGrabbingObject = true;
        grabbingJoint    = hinge;
    }
Example #24
0
 //Update if plane part breaks
 public void OnJointBreak2D(Joint2D thejoint)
 {
     if (thejoint.connectedBody.gameObject.transform.name == "elevator")
     {
         elevator.IsBroken = true;
     }
 }
 void OnDestroy()
 {
     Assert.IsTrue(isDestroyed, "Someone destroyed JointWrapper directly, without calling Destroy()");
     NotifyJointBreak();
     Destroy(joint);
     joint = null;
 }
Example #26
0
    void Start()
    {
        managerScript = gameManager.GetComponent <ResourceProtoManager>();

        //for (int i = 0; i < linkNum; i++)
        if (managerScript.linkCount < managerScript.linkLength)
        {
            Transform nextLink;
            nextLink = Instantiate(ropeLink, new Vector3(1 * 0, 0, 0), Quaternion.identity);
            //-0.525f
            Joint2D nextHJoint = nextLink.gameObject.GetComponent <Joint2D>();
            nextHJoint.connectedBody = this.gameObject.GetComponent <Rigidbody2D>();
            Joint2D nextDJoint = nextLink.gameObject.GetComponent <DistanceJoint2D>();
            nextDJoint.connectedBody = this.gameObject.GetComponent <Rigidbody2D>();
            managerScript.linkCount++;
            //if (managerScript.linkCount == managerScript.linkLength)
            if (managerScript.linkCount == 1)
            {
                //MouseFollow mouseScript = nextLink.gameObject.GetComponent<MouseFollow>();
                MouseFollow mouseScript = this.gameObject.GetComponent <MouseFollow>();
                mouseScript.enabled = true;
                this.gameObject.GetComponent <Joint2D>().enabled         = false;
                this.gameObject.GetComponent <DistanceJoint2D>().enabled = false;
                //nextDJoint.enabled = false;
            }
        }
    }
Example #27
0
 private void OnJointBreak2D(Joint2D joint)
 {
     if (joint == attachmentPointJoint)
     {
         //AddSpringJoint2D();
         DetachFoot();
     }
 }
Example #28
0
 // Use this for initialization
 protected override void Awake()
 {
     player   = GameObject.Find("PlayerSystem/Player");
     joint2d  = GetComponent <Joint2D>();
     isBroken = false;
     audios   = GetComponents <AudioSource>();
     base.Awake();
 }
Example #29
0
 private void OnJointBreak2D(Joint2D joint)
 {
     if (joint == joints[0] || joint == joints[1])
     {
         disableEndPoint1();
         disableEndPoint2();
     }
 }
Example #30
0
 void OnJointBreak2D(Joint2D brokenJoint)
 {
     if (brokenJoint is FixedJoint2D)
     {
         SEventSystem.FireEvent(EventNames.CAR_BRAKE);
         SEventSystem.FireEvent(EventNames.CAR_BRAKE_WITH_VELOCITY, new PMEventArgs(velocityInPrevFrame));
     }
 }
Example #31
0
        private void WriteJointData(XmlWriter xw, Body2D body)
        {
            Joint2D[] jts = new Joint2D[body.Joints.Count];
            body.Joints.Values.CopyTo(jts, 0);
            List<Joint2D> jList = new List<Joint2D>(jts);
            jList.Sort();

            foreach (Joint2D j in jList)
            {
                j.Dump(xw);
            }
        }