示例#1
0
    // Start is called before the first frame update
    void Start()
    {
        for (float i = 0; i < m_ropeLength; i += m_segmentLength)
        {
            AddRopeSegment();
        }

        GameObject   finaldude     = Instantiate(m_finalObject, new Vector3(0, 0, 0), Quaternion.identity);
        FixedJoint2D newFixedJoint = finaldude.GetComponent <FixedJoint2D>();

        newFixedJoint.anchor          = new Vector2(0f, m_segmentLength / 2f);
        newFixedJoint.connectedAnchor = new Vector2(0f, -m_segmentLength / 2f);
        Rigidbody2D lastBody = lastRopeSegment.GetComponent <Rigidbody2D>();

        newFixedJoint.connectedBody = lastBody;

        HingeJoint2D newHingeJoint = finaldude.GetComponent <HingeJoint2D>();

        newHingeJoint.anchor          = new Vector2(0f, m_segmentLength / 2f);
        newHingeJoint.connectedAnchor = new Vector2(0f, -m_segmentLength / 2f);
        newHingeJoint.connectedBody   = lastBody;

        finaldude.transform.position = lastRopeSegment.transform.position;
        finaldude.transform.position = new Vector2(finaldude.transform.localPosition.x, finaldude.transform.localPosition.y - m_segmentLength - m_segmentGap);
        finaldude.transform.SetParent(lastRopeSegment.transform);

        CameraFollow camScript = GetComponent <CameraFollow>();

        camScript.m_cameraFollowTargets.Add(finaldude);
    }
示例#2
0
    void Start()
    {
        isJumping  = false;
        canControl = true;
        //isShootReady = false;
        m_Rigid    = GetComponent <Rigidbody2D>();
        m_Collider = GetComponent <BoxCollider2D>();
        m_Joint    = JointPosition.GetComponent <FixedJoint2D>();

        cannon = JointPosition.GetComponent <ObjectPrefab_CannonHead>();
        CharacterAnimation.OnThrow = ThrowHead;
        CharacterAnimation.OnJump  = Jump;

        sideContactFilter = new ContactFilter2D
        {
            layerMask    = LayerMask.GetMask("Default", "Platform", "Interactable"),
            useLayerMask = true,
            useTriggers  = false,
        };
        bottomContactFilter = new ContactFilter2D
        {
            layerMask    = LayerMask.GetMask("Default", "Platform", "Interactable", "OneWayPlatform"),
            useLayerMask = true,
            useTriggers  = false,
        };
    }
    private void GrabObject()
    {
        Collider2D collider = Physics2D.OverlapCircle(m_WallCheck.position, k_GroundedRadius, m_WhatIsObject);

        if (collider && collider.gameObject != this.gameObject)
        {
            // touching something
            isPushing = true;
            if (isGrabbing)
            {
                FixedJoint2D objectJoint = collider.gameObject.GetComponent <FixedJoint2D>();
                objectJoint.enabled       = true;
                objectJoint.connectedBody = m_Rigidbody2D;
                currentObject             = collider.gameObject;
            }
            else if (currentObject != null)
            {
                FixedJoint2D objectJoint = currentObject.GetComponent <FixedJoint2D>();
                objectJoint.enabled       = false;
                objectJoint.connectedBody = null;
                currentObject             = null;
            }
        }
        else
        {
            isPushing = false;
        }
    }
示例#4
0
        //fix object to background
        public FixedJoint2D AddFixedJoint()
        {
            FixedJoint2D C_HJ2D = gameObject.AddComponent <FixedJoint2D>();

            C_HJ2D.anchor = transform.InverseTransformPoint(transform.position);
            return(C_HJ2D);
        }
示例#5
0
    public void AttachTo(Rigidbody2D target)
    {
        if (endConnection != null)
        {
            Destroy(endConnection);
        }
        var targetCollider = target.GetComponent <Collider2D>();

        for (int i = 0; i < 50; i++)
        {
            var lastSegment  = ropePoints[ropePoints.Count - 1];
            var lastSegPos3  = lastSegment.transform.position;
            var lastSegPos   = new Vector2(lastSegPos3.x, lastSegPos3.y);
            var closestPoint = targetCollider.ClosestPoint(lastSegPos);
            var dist         = (closestPoint - lastSegPos).magnitude;
            if (dist < simulationRadius)
            {
                endConnection = target.gameObject.AddComponent <FixedJoint2D>();
                endConnection.autoConfigureConnectedAnchor = false;
                endConnection.connectedBody   = lastSegment;
                endConnection.connectedAnchor = Vector2.zero;
                endConnection.anchor          = endConnection.transform.InverseTransformPoint(closestPoint);
                return;
            }
            var offset    = (closestPoint - lastSegPos).normalized;
            var movement  = Mathf.Min(resolution, dist);
            var attachPos = lastSegPos3 + (Vector3)(offset * movement);
            AddLink(attachPos);
        }
    }
示例#6
0
 public void BootUp()
 {
     if (knots > 0)
     {
         knots--;
         var child = Instantiate(chainPrefab, tr);
         child.GetComponent <Rigidbody2D>().gravityScale = 0f;
         child.GetComponent <AutoChain>().SetOffset(offsetPosition);
         child.GetComponent <AutoChain>().SetKnot(knots);
         child.GetComponent <AutoChain>().PassHook(hook);
         //var anchorPoint = child.GetComponent<Transform>().position - tr.position;
         //child.GetComponent<HingeJoint2D>().connectedAnchor = anchorPoint ;
         //child.GetComponent<HingeJoint2D>().connectedBody = rb;
         //child.GetComponent<HingeJoint2D>().enabled = true;/*
         child.GetComponent <DistanceJoint2D>().connectedBody = rb;
         child.GetComponent <DistanceJoint2D>().distance      = 0.5f;
         child.GetComponent <DistanceJoint2D>().enabled       = true;
         child.GetComponent <SpriteRenderer>().enabled        = true;
         child.GetComponent <Transform>().transform.position  = tr.position + offsetPosition;
         child.GetComponent <AutoChain>().BootUp();
     }
     else if (knots == 0)
     {
         FixedJoint2D joint = gameObject.AddComponent <FixedJoint2D>();
         joint.connectedBody = hook;
     }
 }
示例#7
0
    public void BallAttach(Rigidbody2D ball)
    {
        FixedJoint2D pfj = GetComponent <FixedJoint2D>();

        pfj.enabled       = true;
        pfj.connectedBody = ball;
    }
示例#8
0
    public override void Init()
    {
        if (currentCollider == null)
        {
            Log("커런트 콜라이더가 없음. 일단 자동으로 넣어볼게");

            var _tempColls = GetComponents <Collider2D>();


            for (int i = 0; i < _tempColls.Length; i++)
            {
                var _tempColl = _tempColls[i];

                if (_tempColl.isTrigger == false)
                {
                    Log("자동으로 콜라이더 넣기 성공. ");
                    currentCollider = _tempColl;
                    break;
                }
            }
        }
        if (fixedJoint == null)
        {
            fixedJoint = GetComponent <FixedJoint2D>();
        }

        if (rigidBody == null)
        {
            GetComponent <Rigidbody2D>();
        }
        fixedJoint.autoConfigureConnectedAnchor = false;
        fixedJoint.enabled = false;

        Physics2D.IgnoreCollision(PlayerController.Instance.playerCollider, currentCollider);
    }
示例#9
0
        public void SetPos()
        {
            FixedJoint2D tj = GetComponent <FixedJoint2D> ();
            Transform    tf = tj.connectedBody.transform;

            transform.position = tf.position;
        }
示例#10
0
    Wheel AddWheel(float xoff, float yoff, bool powered, bool rotatable, bool handbrake)
    {
        Wheel wheel = new Wheel {
            obj       = (GameObject)Instantiate(wheelPrefab, transform),
            powered   = powered,
            rotatable = rotatable,
            handbrake = handbrake,
        };

        wheel.obj.transform.localPosition += new Vector3(xoff, yoff, 0);

        if (rotatable)
        {
            HingeJoint2D hingeJoint = wheel.obj.AddComponent <HingeJoint2D>();
            hingeJoint.connectedBody = gameObject.GetComponent <Rigidbody2D>();
            hingeJoint.useLimits     = true;
            hingeJoint.limits        = new JointAngleLimits2D()
            {
                max = maxWheelAngle, min = -maxWheelAngle
            };
            hingeJoint.useMotor = true;
        }
        else
        {
            FixedJoint2D fixedJoint = wheel.obj.AddComponent <FixedJoint2D>();
            fixedJoint.connectedBody = gameObject.GetComponent <Rigidbody2D>();
        }

        return(wheel);
    }
示例#11
0
    // Use this for initialization
    void Start()
    {
        joint = tip.GetComponent <FixedJoint2D> ();

        //get the original size of the sprite, unscaled, to use later
        originalSize = springRenderer.sprite.bounds.size;
    }
示例#12
0
 // Start is called before the first frame update
 void Start()
 {
     m_SoundManager      = GetComponent <SoundManager>();
     m_ConnectingJoint2D = null;
     m_GrabbableScript   = null;
     _grabDisabledTime   = 0;
 }
示例#13
0
 void FixedUpdate()
 {
     if (Input.GetMouseButton(0))
     {
         Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit))
         {
             m_targetJoint.target = new Vector2(hit.point.x, hit.point.y);
         }
     }
     else if (Input.GetMouseButtonUp(0))
     {
         if (m_ballAttached == true)
         {
             m_ballAttached = false;
             FixedJoint2D joint = GetComponent <FixedJoint2D> ();
             if (joint != null)
             {
                 joint.breakForce = 0;
                 m_gameController.PaddleReleaseBall();
             }
         }
     }
     if (m_cannonAttached == true)
     {
         m_deltaTime += Time.deltaTime;
         if (m_deltaTime > 1.0)
         {
             m_gameController.AddBullet();
             //Debug.Log("Fire bullet");
             m_deltaTime = 0.0f;
         }
     }
 }
示例#14
0
    public void TrySpawnCrate()
    {
        if (holdingCrate || holdingDownInput)
        {
            return;
        }

        holdingCrate = true;
        GameObject crate = null;

        if (firstCratePlayer && !playerCrateDropped)
        {
            crate = Instantiate(playerCrateObj, transform);
            playerCrateDropped = true;
        }
        else
        {
            crate = Instantiate(crateObjs[Random.Range(0, crateObjs.Length)], transform);
        }
        heldCrate = crate.transform;

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

        fixedJoint.autoConfigureConnectedAnchor = false;

        fixedJoint.anchor          = Vector2.zero;
        fixedJoint.connectedAnchor = new Vector2(0, -1.15f);

        fixedJoint.connectedBody = clawRB;
    }
示例#15
0
    void Update()
    {
        if (zerbrechlich)
        {
            angle = zerbrechlich.GetComponent <HingeJoint2D> ().jointAngle;
        }

        if (kaputt)
        {
            if (angle <= 0 && angle >= -1)
            {
                interaktiv1FJ.AddComponent <FixedJoint2D> ();
                neu_fj_interaktiv1 = interaktiv1FJ.GetComponent <FixedJoint2D> ();

                neu_fj_interaktiv1.connectedBody = zerbrechlich.GetComponent <Rigidbody2D>();
                neu_fj_interaktiv1.autoConfigureConnectedAnchor = true;
                neu_fj_interaktiv1.breakForce  = 2000;
                neu_fj_interaktiv1.breakTorque = 2000;

                neu_fj_interaktiv1.anchor = manager.anchorLager;

                kaputt = false;
            }
        }
    }
示例#16
0
    // Start is called before the first frame update
    protected void Start()
    {
        base.Start();
        if (gameController == null)
        {
            gameController = GameObject.Find("GameController").GetComponent <GameController>();
        }
        defaultBulletSprtite = Resources.Load <Sprite>("bullet/hammer");
        bulletJoint          = this.GetComponent <FixedJoint2D>();

        ClothSprite = this.FindChildObject("ClothSprite").GetComponent <EquipController>();
        FaceSprite  = this.FindChildObject("FaceSprite").GetComponent <EquipController>();
        HairSprite  = this.FindChildObject("HairSprite").GetComponent <EquipController>();
        ArmSprite   = this.FindChildObject("ArmSprite").GetComponent <EquipController>();

        if (staticBullet == null)
        {
            staticBullet = this.FindChildObject("StaticBullet");
        }

        anim = transform.GetChild(1).gameObject.GetComponent <Animator>();
        if (info != null)
        {
            if (info.direction > 180)
            {
                this.RotateLiving();
            }
        }
    }
示例#17
0
 // Start is called before the first frame update
 void Start()
 {
     rb                   = this.GetComponent <Rigidbody2D>();
     buitreSprite         = this.GetComponent <SpriteRenderer>();
     fixJoint             = this.GetComponent <FixedJoint2D>();
     flightsTextMesh.text = buitreMaxFlightCount.ToString();
 }
示例#18
0
    private void attachSticker()
    {
        if (this._stickStart == null || this._stickEnd == null)
        {
            return;
        }

        GameObject start = this._stickStart.gameObject;
        GameObject end   = this._stickEnd.gameObject;

        Rigidbody2D startBody = start.GetComponent <Rigidbody2D>();
        Rigidbody2D endBody   = end.GetComponent <Rigidbody2D>();

        if (startBody == null && endBody == null)
        {
            return;                                       // Both static, no need for sticker
        }
        if (startBody == null)
        {
            start     = this.setStaticGluePos(this._stickStart.transform.position);
            startBody = start.GetComponent <Rigidbody2D>();
        }
        else if (endBody == null)
        {
            end     = this.setStaticGluePos(this._stickEnd.transform.position);
            endBody = end.GetComponent <Rigidbody2D>();
        }

        this._stickJoint = end.gameObject.AddComponent <FixedJoint2D>();
        this._stickJoint.autoConfigureConnectedAnchor = true;
        this._stickJoint.connectedBody = startBody;
    }
示例#19
0
    public void BallRelease()
    {
        FixedJoint2D pfj = GetComponent <FixedJoint2D>();

        pfj.enabled = false;
        m_levelEntities.SoundBallLaunch();
    }
示例#20
0
    void Start()
    {
        limb       = GetComponentInParent <Limb>();
        controller = GetComponentInParent <StickmanController>();
        ig         = GetComponentInParent <IgnoreCollision>();
        var circleColl = gameObject.AddComponent <CircleCollider2D>();

        circleColl.radius = .05f;
        coll = circleColl;
        if (ig)
        {
            ig.IgnoreCollider(coll);
        }

        rb = GetComponent <Rigidbody2D>();

        parent = transform;
        while (parent.parent)
        {
            parent = parent.parent;
        }
        mask          = ~LayerMask.GetMask("Moveable");
        joint         = gameObject.AddComponent <FixedJoint2D>();
        joint.enabled = false;
    }
示例#21
0
    public void GrabWagon()
    {
        var wagons        = GameObject.FindGameObjectsWithTag(wagonTag);
        var bodyColliders = GetComponentsInChildren <Collider2D>();

        foreach (var wagon in wagons)
        {
            foreach (var collider in wagon.GetComponentsInChildren <Collider2D>())
            {
                foreach (var bodyCollider in bodyColliders)
                {
                    if (bodyCollider.IsTouching(collider))
                    {
                        isWagonGrabbed = true;
                        wagonGrabbed   = wagon;
                        var wagonrb2d = wagonGrabbed.GetComponent <Rigidbody2D>();
                        wagonrb2d.isKinematic = false;

                        wagoncharacterjoint = gameObject.AddComponent <FixedJoint2D>();
                        wagoncharacterjoint.connectedBody   = wagonrb2d;
                        wagoncharacterjoint.connectedAnchor = wagonrb2d.transform.position;
                        return;
                    }
                }
            }
        }
    }
示例#22
0
    // Called for each section that we're creating a tiled version for
    GameObject TileItHere(Vector2 coordOffset, GameObject original)
    {
        Rigidbody2D rb = original.GetComponent <Rigidbody2D> ();

        if (rb == null)
        {
            return(null);
        }

        Vector3    originalPos = original.transform.position;
        Quaternion originalRot = original.transform.rotation;

        coordOffset += new Vector2(originalPos.x, originalPos.y);
        Vector3    spawnPos = new Vector3(coordOffset.x, coordOffset.y, cam.nearClipPlane);
        GameObject obj      = Instantiate(original, spawnPos, originalRot) as GameObject;

        obj.name = original.name;

        // Fix joints on asteroids
        if (obj.tag != "Player")
        {
            FixedJoint2D cJ = obj.AddComponent <FixedJoint2D> ();
            cJ.autoConfigureConnectedAnchor = true;
            cJ.connectedBody = rb;
            obj.layer        = LayerMask.NameToLayer("Asteroid");
            obj.tag          = "Asteroid";
        }

        // These are clones
        obj.GetComponent <ObjectTilingCtrl> ().isOriginal = false;
        return(obj);
    }
示例#23
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);
    }
    void stickToObject(GameObject go)
    {
        Rigidbody2D goRB2D = go.GetComponent <Rigidbody2D>();

        if (goRB2D)
        {
            bool foundObj = false;
            foreach (FixedJoint2D fj2d in GetComponents <FixedJoint2D>())
            {
                if (fj2d.connectedBody == goRB2D)
                {
                    foundObj = true;
                    break;
                }
            }
            if (!foundObj)
            {
                FixedJoint2D fj2d = gameObject.AddComponent <FixedJoint2D>();
                fj2d.connectedBody = goRB2D;
                fj2d.autoConfigureConnectedAnchor = false;
            }
        }
        else
        {
            if (!connectedObjs.Contains(go.name))
            {
                TargetJoint2D tj2d = gameObject.AddComponent <TargetJoint2D>();
                tj2d.autoConfigureTarget = false;
                rb2d.constraints         = RigidbodyConstraints2D.FreezeAll;
                connectedObjs.Add(go.name);
            }
        }
    }
示例#25
0
 public void Wench(float amount)
 {
     if (ropeSegments.Count == 0)
     {
         return;
     }
     if (ropeSegments[0].distance < wenchTolerance / 2)
     {
         // If we have effectively connect the start point and the next point, then we
         // want to check for the two bodies actually being close together
         float dist = (ropePoints[0].position - ropePoints[1].position).magnitude;
         if (dist < wenchTolerance)
         {
             // Now we will remove the second rope point and update the connection of the
             // next rope point to the start. But first we need to see if we are removing
             // the end rope point.
             if (ropeSegments.Count == 1)
             {
                 // If we are dragging and object, then anchor that object to the
                 // start node. So if we give it lenience, it will be pulled back out.
                 if (endConnection != null)
                 {
                     var newEndConnection = endConnection.gameObject.AddComponent <FixedJoint2D>();
                     newEndConnection.autoConfigureConnectedAnchor = false;
                     newEndConnection.connectedBody   = ropePoints[0];
                     newEndConnection.connectedAnchor = Vector2.zero;
                     newEndConnection.anchor          = endConnection.anchor;
                     // Destroy the attachment to ropePoints[1].
                     Destroy(endConnection);
                     endConnection = newEndConnection;
                 }
             }
             else
             {
                 // Otherwise, there is another point. Attach that point to the base point and
                 // remove the old connection. Keep the current distance between the second point
                 // and base point as their distance for now. It will be wenched together later.
                 var newJoint = ropePoints[2].gameObject.AddComponent <DistanceJoint2D>();
                 newJoint.autoConfigureConnectedAnchor = false;
                 newJoint.autoConfigureDistance        = false;
                 newJoint.connectedBody   = ropePoints[0];
                 newJoint.connectedAnchor = Vector2.zero;
                 newJoint.anchor          = Vector2.zero;
                 newJoint.maxDistanceOnly = true;
                 newJoint.distance        = (ropePoints[0].position - ropePoints[2].position).magnitude;
                 Destroy(ropeSegments[1]);
                 ropeSegments[1] = newJoint;
             }
             Destroy(ropePoints[1].gameObject);
             ropePoints.RemoveAt(1);
             ropeSegments.RemoveAt(0);
         }
     }
     for (int i = 0; (i < ropeSegments.Count) && (amount >= 0.001 * wenchTolerance); i++)
     {
         var change = Mathf.Min(amount, ropeSegments[i].distance - 0.005f);
         ropeSegments[i].distance -= change;
         amount -= change;
     }
 }
示例#26
0
 public PushableBlock(GameObject newGo)
 {
     Transform = newGo.transform;
     Collider  = newGo.GetComponent <BoxCollider2D>();
     Rigidbody = newGo.GetComponent <Rigidbody2D>();
     Joint     = newGo.GetComponent <FixedJoint2D>();
 }
    void Update()
    {
        if (DrawBegin())
        {
            GameObject prefab = CreateBallPrefab(GetWorldPositionFromMousePosition());

            previousSegment = prefab;
            allSegments.Add(prefab);
        }
        else if (DrawIsInProgress())
        {
            Vector3 currentPosition = camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, camera.nearClipPlane));

            if (currentPosition.Equals(previousSegment.transform.position))
            {
                return;
            }

            GameObject prefab = CreateBallPrefab(currentPosition);

            FixedJoint2D joint = prefab.AddComponent <FixedJoint2D> ();
            joint.connectedBody = previousSegment.GetComponent <Rigidbody2D> ();

            previousSegment = prefab;
            allSegments.Add(prefab);
        }
        else if (DrawEnded())
        {
            StartCoroutine("ActivateSegments");
        }
    }
示例#28
0
 public void PlatformJoint(GameObject platform)
 {
     fj                 = GetComponent <FixedJoint2D>();
     fj.enabled         = true;
     fj.connectedBody   = platform.GetComponent <Rigidbody2D>();
     fj.connectedAnchor = connectedAnchor;
 }
示例#29
0
    private void DrawCarrot(Vector2Int chunkCoord, InfiniteChunks.Chunk chunk, GameObject asteroid, int asteroidSize)
    {
        GameObject carrot = carrotPool.GetFromPool(0);

        if (carrot == null)
        {
            return;
        }

        Vector2 dir = Random.insideUnitCircle.normalized * (asteroidSize + 1);

        carrot.transform.position = asteroid.transform.position + asteroid.transform.TransformDirection(dir);

        Vector3 targetRotateDir = asteroid.transform.position - carrot.transform.position;
        float   angle           = (Mathf.Atan2(targetRotateDir.y, targetRotateDir.x) * Mathf.Rad2Deg) - 90f;

        carrot.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

        FixedJoint2D joint = carrot.GetComponent <FixedJoint2D>();

        joint.connectedBody = asteroid.GetComponent <Rigidbody2D>();

        Carrot script = carrot.GetComponent <Carrot>();

        script.SetPickupCallback(CarrotPickup, chunkCoord);
        carrot.SetActive(true);
        chunk.AddCarrot(carrot);
    }
    public void LinkJointToNeighbor(GameObject neighbor)
    {
        FixedJoint2D joint = transform.gameObject.AddComponent <FixedJoint2D> ();

        joint.connectedBody = neighbor.GetComponent <Rigidbody2D> ();
        Debug.Log("From " + joint.transform.gameObject + " to " + neighbor);
    }