Exemple #1
0
    public static void SeverTentacle(Tentacle tentacle)
    {
        int severPoint = (int)Mathf.Ceil(tentacle.segments * Random.Range(0.2f, 0.5f));

        Tentacle baseHalf = Ungenerated();

        CopyTentSubSegments(tentacle, baseHalf, 0, severPoint);
        baseHalf.AttachBase(tentacle.connectBody);
        Transform endPoint = baseHalf.transform.Find("EndPoint");

        MakeEndDangling(endPoint);
        SpringJoint2D endSpringJoint = endPoint.GetComponent <SpringJoint2D>();

        endSpringJoint.connectedBody = tentacle.connectBody;
        endSpringJoint.distance      = tentacle.length * ((float)severPoint / (float)tentacle.segments) * 0.5f;

        Tentacle endHalf = Ungenerated();

        CopyTentSubSegments(tentacle, endHalf, severPoint, tentacle.segments - 1);
        MakeEndDangling(endHalf.transform);
        if (tentacle.Grabbing)
        {
            endHalf.AttachEnd(tentacle.endAttachSpring.connectedBody, tentacle.GetEndPosition());
        }
        else
        {
            Transform endHalfEndPoint = endHalf.transform.Find("EndPoint");
            MakeEndDangling(endHalfEndPoint);
            SpringJoint2D endHalfEndSpring = endHalfEndPoint.gameObject.GetComponent <SpringJoint2D>();
            endHalfEndSpring.enabled = false;

            Rigidbody2D endBody = endHalf.gameObject.GetComponent <Rigidbody2D>();
            endBody.gravityScale = 1;
            Rigidbody2D endPointBody = endHalfEndPoint.gameObject.GetComponent <Rigidbody2D>();
            endPointBody.gravityScale = 1;
        }
        SpringJoint2D spring = endHalf.gameObject.GetComponent <SpringJoint2D>();

        spring.connectedBody = endHalf.transform.Find("EndPoint").gameObject.GetComponent <Rigidbody2D>();
        spring.distance      = (tentacle.length - endSpringJoint.distance) * 0.5f;

        ExplosionManager.BloodSplatter(tentacle.tentJoints[severPoint].transform.position, 3, 0);

        tentacle.StopGrabbing();
        GameObject.Destroy(tentacle.gameObject);
    }
Exemple #2
0
    void RemoveRopeSegment()
    {
        if (ropeSegments.Count < 2)
        {
            return;
        }

        GameObject topSegment  = ropeSegments[0];
        GameObject nextSegment = ropeSegments[1];

        SpringJoint2D nextSegmentJoint = nextSegment.GetComponent <SpringJoint2D>();

        nextSegmentJoint.connectedBody = this.GetComponent <Rigidbody2D>();

        ropeSegments.RemoveAt(0);
        Destroy(topSegment);
    }
Exemple #3
0
    void CreateRopeSegment()
    {
        GameObject segment = (GameObject)Instantiate(ropeSegmentPrefab,

                                                     this.transform.position, Quaternion.identity);

        segment.transform.SetParent(this.transform, true);

        Rigidbody2D segmentBody = segment.GetComponent <Rigidbody2D>();

        SpringJoint2D segmentJoint =
            segment.GetComponent <SpringJoint2D>();

        if (segmentBody == null || segmentJoint == null)
        {
            Debug.LogError("Rope segment body prefab has no " +
                           "Rigidbody2D and/or SpringJoint2D!");
            return;
        }

        ropeSegments.Insert(0, segment);

        if (ropeSegments.Count == 1)
        {
            SpringJoint2D connectedObjectJoint =
                connectedObject.GetComponent <SpringJoint2D>();

            connectedObjectJoint.connectedBody = segmentBody;
            connectedObjectJoint.distance      = 0.1f;

            segmentJoint.distance = maxRopeSegmentLength;
        }
        else
        {
            GameObject nextSegment = ropeSegments[1];

            SpringJoint2D nextSegmentJoint =
                nextSegment.GetComponent <SpringJoint2D>();

            nextSegmentJoint.connectedBody = segmentBody;

            segmentJoint.distance = 0.0f;
        }
        segmentJoint.connectedBody = this.GetComponent <Rigidbody2D>();
    }
Exemple #4
0
    // Update is called once per frame
    void Update()
    {
        Vector3 mouse3d = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector2 mouse2d = new Vector2(mouse3d.x, mouse3d.y);

        if (Input.GetMouseButtonDown(0))
        {
            Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);

            // If it hits something...
            if (hit.collider != null)
            {
                grabbedobj = hit.collider.GetComponent <Rigidbody2D>();
                SJ2D       = grabbedobj.gameObject.AddComponent <SpringJoint2D> ();
                SJ2D.autoConfigureDistance = false;
                LCLHTPNT             = grabbedobj.transform.InverseTransformPoint(hit.point);
                SJ2D.anchor          = LCLHTPNT;
                SJ2D.enableCollision = true;
                SJ2D.distance        = 0.5f;
                SJ2D.dampingRatio    = 1f;
                SJ2D.frequency       = 1;
                SJ2D.connectedBody   = null;



                LR.enabled = true;
            }
        }
        if (Input.GetMouseButtonUp(0) && grabbedobj != null)
        {
            Destroy(SJ2D);
            LR.enabled = false;
            grabbedobj = null;
        }

        if (SJ2D != null)
        {
            SJ2D.connectedAnchor = mouse3d;
        }
        else
        {
            LR.enabled = false;
        }
    }
Exemple #5
0
    private void FixedUpdate()
    {
        if (ReplayControl.touchable)
        {
            return;
        }
        for (int i = 0; i < 2; i++)
        {
            SpringJoint2D joint = joints[i];
            if (joint != null && joint.enabled)
            {
                float springLength = this.getSpringLength();
                float x            = springLength - this.elength;
                float k            = this.springConstant;

                if (Math.Abs((double)x * (double)k) >= breakforce)
                {
                    this.gameObject.GetComponent <Destructable>().Destruct();
                }

                Vector3 dirup   = this.trans.TransformDirection(Vector3.up).normalized;
                Vector3 dirdown = this.trans.TransformDirection(Vector3.down).normalized;

                Vector2 reactionForce = joint.reactionForce;

                if (endPoint1.gameObject == joint.attachedRigidbody.gameObject)
                {
                    joint.attachedRigidbody.AddForce(reactionForce);
                    joint.connectedBody.AddForce(-1f * reactionForce);

                    joint.attachedRigidbody.AddForce((-k * x) * dirup, ForceMode2D.Force);
                    joint.connectedBody.AddForce((-k * x) * dirdown, ForceMode2D.Force);
                }
                else if (endPoint1.gameObject == joint.connectedBody.gameObject)
                {
                    joint.attachedRigidbody.AddForce(reactionForce);
                    joint.connectedBody.AddForce(-1f * reactionForce);

                    joint.connectedBody.AddForce((-k * x) * dirup, ForceMode2D.Force);
                    joint.attachedRigidbody.AddForce((-k * x) * dirdown, ForceMode2D.Force);
                }
                configureJoints();
            }
        }
    }
Exemple #6
0
    // Called when we've shrunk the rope, and
    // we need to remove a segment.
    void RemoveRopeSegment()
    {
        // If we don't have two or more segments, stop.
        if (ropeSegments.Count < 2)
        {
            return;
        }
        // Get the top segment, and the segment under it.
        GameObject topSegment  = ropeSegments[0];
        GameObject nextSegment = ropeSegments[1];
        // Connect the second segment to the rope's anchor.
        SpringJoint2D nextSegmentJoint = nextSegment.GetComponent <SpringJoint2D>();

        nextSegmentJoint.connectedBody = this.GetComponent <Rigidbody2D>();
        // Remove the top segment and destroy it.
        ropeSegments.RemoveAt(0);
        Destroy(topSegment);
    }
Exemple #7
0
    private void SpawnNewBall()
    {
        //* ballPrefab - the thing that we want to spawn
        //* anchorPoint.position - the position where we want to spawn the object
        //* Quaternion.identity - the rotation of the object, (that we don`t care about)
        //! rotations are stored in this datatype called Quaternion (which get all weird because it has x,y,z and w so to prevent the weird things??? we can use the .identity which means the default rotation(need to see the documentation!!!!!!))
        //! instantiate returns a game object which is the instance we just spawned in
        GameObject ballInstance = Instantiate(ballPrefab, anchorPoint.position, Quaternion.identity);

        // in the <> in the method GetComponent we put the type of component we want to get
        //! we are declaring the  variables and the type at line 17 - 18
        currentBallRigidbody = ballInstance.GetComponent <Rigidbody2D>();
        currentSPringJoint   = ballInstance.GetComponent <SpringJoint2D>();

        // attached the rigid body to the anchorPoint
        //! we've done this in the inspector with drag and drop when we where serializing these fields but now when they are not serialized fields we must connect them here
        currentSPringJoint.connectedBody = anchorPoint;
    }
 void Start()
 {
     ParentCatapault            = transform.parent.gameObject;
     spring                     = GetComponent <SpringJoint2D>();
     catapult                   = spring.connectedBody.transform;
     CatapultLineBack.material  = materials[0];
     CatapultLineFront.material = materials[0];
     startLocation              = transform.position;
     LineRendererSetup();
     rayToMouse = new Ray(catapult.position, Vector3.zero);
     leftCatapultToProjectile = new Ray(CatapultLineFront.transform.position, Vector3.zero);
     maxStretchSqr            = MaxStretch * MaxStretch;
     circle        = GetComponent <Collider2D>() as CircleCollider2D;
     circleRadius  = circle.radius;
     newSpring     = this.GetComponent <SpringJoint2D>();
     connectedBody = GetComponent <SpringJoint2D>().connectedBody;
     LineRendererUpdate();
 }
Exemple #9
0
    private void SpawnBoneFields()
    {
        BoneFields = new List <GameObject>();

        for (int i = 0; i < NumberOfFields; i++)
        {
            GameObject newBoneField = GameObject.Instantiate(BoneFieldPrefab);
            newBoneField.transform.position   = transform.position;
            newBoneField.transform.localScale = new Vector3(BoneFieldSize, BoneFieldSize, BoneFieldSize);
            SpringJoint2D jointRef = newBoneField.GetComponent <SpringJoint2D>();
            jointRef.connectedBody = GetComponent <Rigidbody2D>();
            jointRef.distance      = FieldSpringDistance;
            jointRef.dampingRatio  = FieldSpringDampingRatio;
            jointRef.frequency     = FieldSpringFrequency;

            BoneFields.Add(newBoneField);
        }
    }
Exemple #10
0
    void Start()
    {
        em = GameObject.Find("EventManager").GetComponent <EventManager>();

        rb          = GetComponent <Rigidbody2D>();
        rb.velocity = new Vector2(10f, 0f);
        spring      = GetComponent <SpringJoint2D>();

        // Set camera default position
        cameraTargetPos  = new Vector3(transform.position.x, transform.position.y, -115f);
        cameraTargetSize = 50f;

        anim = GetComponent <Animator>();

        // Set speed slider limits
        speedSlider.maxValue = maxSpeed;
        speedSlider.minValue = minSpeed;
    }
Exemple #11
0
    void Start()
    {
        Ball_Rigidbody        = GetComponent <Rigidbody2D>();
        Ball_LİneRenderer     = GetComponent <LineRenderer>();
        Ball_TrailRenderer    = GetComponent <TrailRenderer>();
        Ball_SpringJoint      = GetComponent <SpringJoint2D>();
        Hook_Object_Rigidbody = GetComponent <Rigidbody2D>();

        Ball_LİneRenderer.enabled = false;
        Ball_ReleaseDelay         = 1 / (Ball_SpringJoint.frequency * 4);

        Hook_Object_Rigidbody = Ball_SpringJoint.connectedBody;

        Not_Pushed_Button_Object.SetActive(true);
        Pushed_Button_Object.SetActive(false);

        isPressed = false;
    }
Exemple #12
0
    public void AttachToGrapple(GameObject object_containing_sprintjoint, float max_distance)
    {
        if (is_climbing_rope)
        {
            DetachFromRope(false);
        }

        is_grappling     = true;
        is_climbing_rope = true;

        max_hooking_distance = max_distance;
        spring               = object_containing_sprintjoint.GetComponent <SpringJoint2D>();
        spring.enabled       = true;
        spring.connectedBody = m_Rigidbody2D;
        cur_distance         = Vector2.Distance(this.transform.position, spring.gameObject.transform.position);
        spring.distance      = cur_distance;
        this.m_AirControl    = false;
    }
Exemple #13
0
    private void InitializeStabilizers(Rigidbody2D leftRigidBody, Rigidbody2D rightRigidBody)
    {
        centerPoint = _joints[_joints.Count / 2];
        GameObject leftStabilizePointGo  = GameObject.Find("leftStabilizePoint");
        GameObject rightStabilizePointGo = GameObject.Find("rightStabilizePoint");

        leftStabilizePoint  = leftStabilizePointGo.GetComponent <SpringJoint2D>();
        rightStabilizePoint = rightStabilizePointGo.GetComponent <SpringJoint2D>();
        GetComponentInChildren <Stabilizer>().SetAnchor(centerPoint.transform);
        leftStabilizePoint.connectedBody          = leftRigidBody;
        rightStabilizePoint.connectedBody         = rightRigidBody;
        leftStabilizePoint.autoConfigureDistance  = false;
        rightStabilizePoint.autoConfigureDistance = false;
        leftStabilizePoint.distance  = 0.01f;
        rightStabilizePoint.distance = 0.01f;
        leftStabilizePoint.enabled   = false;
        rightStabilizePoint.enabled  = false;
    }
Exemple #14
0
    public static void MakeEndDangling(Transform end)
    {
        Rigidbody2D endBody = end.GetComponent <Rigidbody2D>();

        endBody.bodyType     = RigidbodyType2D.Dynamic;
        endBody.mass         = 0.000001f;
        endBody.gravityScale = 11;
        endBody.drag         = 1;
        endBody.AddForce(new Vector2(Random.Range(-.001f, .001f), Random.Range(-.001f, .001f)), ForceMode2D.Impulse);
        SpringJoint2D spring = end.GetComponent <SpringJoint2D>();

        spring.dampingRatio = .4f;
        spring.frequency    = 1.0f;

        //CircleCollider2D circle = end.gameObject.AddComponent<CircleCollider2D>();
        //circle.radius = .2f;
        //end.gameObject.layer = LayerMask.NameToLayer("BackgroundObjects");
    }
        public new void OnSceneGUI()
        {
            SpringJoint2D springJoint2D = (SpringJoint2D)this.target;

            if (!springJoint2D.enabled)
            {
                return;
            }
            Vector3 anchor = Joint2DEditor.TransformPoint(springJoint2D.transform, springJoint2D.anchor);
            Vector3 vector = springJoint2D.connectedAnchor;

            if (springJoint2D.connectedBody)
            {
                vector = Joint2DEditor.TransformPoint(springJoint2D.connectedBody.transform, vector);
            }
            Joint2DEditor.DrawDistanceGizmo(anchor, vector, springJoint2D.distance);
            base.OnSceneGUI();
        }
Exemple #16
0
    void Start()
    {
        // Zoom Animation Object
        efxZoomAniController  = efxZoomObj.GetComponent <AnimateController>();
        efxLightAniController = efxLightObj.GetComponent <AnimateController>();

        // Zoom Light Object
        efxZoomRenderer  = efxZoomObj.GetComponent <Renderer>() as SpriteRenderer;
        efxLightRenderer = efxLightObj.GetComponent <Renderer>() as SpriteRenderer;

        // Sounds
        sounds     = GameObject.Find("SoundObjects").GetComponent <SoundController>();
        pullSound  = sounds.pulldown;
        shootSound = sounds.zonar;

        springJoint          = GetComponent <SpringJoint2D>();
        springJoint.distance = 1f;
    }
Exemple #17
0
        private void Start()
        {
            _gameManager  = GameManager_2.Instance;
            _soundManager = SoundManager_2.Instance;

            _spring = GetComponent <SpringJoint2D>();
            _projectileRigidbody = GetComponent <Rigidbody2D>();

            _slingshot = _spring.connectedBody.transform;

            LineRendererSetup();

            _raySlingshotToTouch = new Ray(_slingshot.position, Vector3.zero);

            _fireworkCurrentCount = _fireworkMaxCount;

            _fireworkEffect = transform.Find("FireworkEffect").GetComponent <ParticleSystem>();
        }
Exemple #18
0
    void setThread()
    {
        Vector3 destinationPosition = threadEnd.transform.position;
        Vector3 originPosition      = threadSource.transform.position;
        Vector3 direction           = destinationPosition - originPosition;

        RaycastHit2D hit = Physics2D.Raycast(originPosition, direction, Mathf.Infinity);

        if (hit.collider != null)
        {
            SpringJoint2D newThread = threadSource.AddComponent <SpringJoint2D> ();

            newThread.enableCollision = false;
            newThread.frequency       = .2f;
            newThread.connectedAnchor = hit.point;
            newThread.enabled         = true;
        }
    }
Exemple #19
0
        public new void OnSceneGUI()
        {
            SpringJoint2D target = (SpringJoint2D)this.target;

            if (!target.enabled)
            {
                return;
            }
            Vector3 anchor  = Joint2DEditor.TransformPoint(target.transform, (Vector3)target.anchor);
            Vector3 vector3 = (Vector3)target.connectedAnchor;

            if ((bool)((Object)target.connectedBody))
            {
                vector3 = Joint2DEditor.TransformPoint(target.connectedBody.transform, vector3);
            }
            Joint2DEditor.DrawDistanceGizmo(anchor, vector3, target.distance);
            base.OnSceneGUI();
        }
Exemple #20
0
    // Вызывается, когда нужно укоротить веревку,
    // и удаляет звено сверху.
    void RemoveRopeSegment()
    {
        // Если звеньев меньше двух, выйти.
        if (ropeSegments.Count < 2)
        {
            return;
        }
        // Получить верхнее звено и звено под ним.
        GameObject topSegment  = ropeSegments[0];
        GameObject nextSegment = ropeSegments[1];
        // Соединить второе звено с опорой для веревки.
        SpringJoint2D nextSegmentJoint = nextSegment.GetComponent <SpringJoint2D>();

        nextSegmentJoint.connectedBody = this.GetComponent <Rigidbody2D>();
        // Удалить верхнее звено из списка и уничтожить его.
        ropeSegments.RemoveAt(0);
        Destroy(topSegment);
    }
Exemple #21
0
    public void Awake()
    {
        this.player     = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform>();
        this.leftJoint  = this.leftJointRb.GetComponent <SpringJoint2D>();
        this.rightJoint = this.rightJointRb.GetComponent <SpringJoint2D>();

        Rigidbody2D playerBody = player.GetComponent <Rigidbody2D>();

        leftJoint.connectedBody  = playerBody;
        rightJoint.connectedBody = playerBody;

        float cameraWidth = (Camera.main.orthographicSize * 2) * Camera.main.aspect;

        this.positionX = cameraWidth / 4;

        SetPosition(this.leftJointRb, -positionX, player.position.y);
        SetPosition(this.rightJointRb, positionX, player.position.y);
    }
Exemple #22
0
    void Update()
    {
        GameObject    topSegment      = ropeSegments[0];
        SpringJoint2D topSegmentJoint = topSegment.GetComponent <SpringJoint2D>();

        if (isIncreasing)
        {
            if (topSegmentJoint.distance >= maxRopeSegmentLength)
            {
                CreateRopeSegment();
            }
            else
            {
                topSegmentJoint.distance += ropeSpeed * Time.deltaTime;
            }
        }

        if (isDecreasing)
        {
            if (topSegmentJoint.distance <= 0.005f)
            {
                RemoveRopeSegment();
            }
            else
            {
                topSegmentJoint.distance -= ropeSpeed * Time.deltaTime;
            }
        }

        if (lineRenderer != null)
        {
            lineRenderer.positionCount = ropeSegments.Count + 2;

            lineRenderer.SetPosition(0, this.transform.position);

            for (int i = 0; i < ropeSegments.Count; i++)
            {
                lineRenderer.SetPosition(i + 1, ropeSegments[i].transform.position);
            }

            SpringJoint2D connectedObjectJoint = connectedObject.GetComponent <SpringJoint2D>();
            lineRenderer.SetPosition(ropeSegments.Count + 1, connectedObject.transform.TransformPoint(connectedObjectJoint.anchor));
        }
    }
Exemple #23
0
    // Use this for initialization
    void Start()
    {
        lines = new List <GameObject> ();

        string[] words = InputText.Split(' ');

        int curIndex = 0;

        foreach (string word in words)
        {
            GameObject t = Instantiate(text, transform.position, Quaternion.identity) as GameObject;
//			t.GetComponent<LinkUp>().myNum = curIndex;
            curIndex++;
            lines.Add(t);
            TextMesh tm = (TextMesh)t.gameObject.GetComponent(typeof(TextMesh));
            tm.text = word;
            Destroy(t.GetComponent <BoxCollider2D>());
            t.AddComponent <BoxCollider2D>();
        }

        for (int i = 0; i < words.Length; i++)
        {
            if (i != words.Length - 1)
            {
                int nextLine = i + 1;

                SpringJoint2D joint = lines[i].gameObject.GetComponent <SpringJoint2D>();

                joint.connectedBody = lines[nextLine].gameObject.rigidbody2D;
//				joint.enabled = false;

                Debug.Log(words[i] + " connects " + words[nextLine]);
            }
            else
            {
                Destroy(lines[i].gameObject.GetComponent <SpringJoint2D>());
            }

            if (i == 0)
            {
                mouse.GetComponent <SpringJoint2D>().connectedBody = lines[i].rigidbody2D;
            }
        }
    }
Exemple #24
0
    void OnCollisionEnter2D(Collision2D c)
    {
        if (this.isInSpace() == false)
        {
            return;
        }

        Vector2 hitPoint = c.contacts[0].point;

        this.ownRigidbody.drag = dragOnComets;

        cometJoint = gameObject.AddComponent <SpringJoint2D> () as SpringJoint2D;
        cometJoint.enableCollision = true;
        cometJoint.frequency       = springForce;
        cometJoint.dampingRatio    = damper;
        cometJoint.anchor          = gameObject.transform.InverseTransformPoint(hitPoint);
        cometJoint.connectedBody   = c.rigidbody;
        cometJoint.connectedAnchor = c.gameObject.transform.InverseTransformPoint(hitPoint);
        cometJoint.distance        = distanceFromComet;

        this.timeOnComet          = 0;
        this.scoredOnCurrentComet = false;
        this.attachedComet        = cometJoint.connectedBody.GetComponent <CometScript> ();

        int layer = LayerMask.NameToLayer("LinkedCharacter");

        gameObject.layer = layer;
        this.attachedComet.gameObject.layer = layer;

        this.canReleaseFromComet = false;
        Hashtable h = new Hashtable();

        h.Add("from", cometReleaseCooldown);
        h.Add("to", cometReleaseCooldown);
        h.Add("time", cometReleaseCooldown);
        h.Add("onupdate", "OnTweenUpdateCometReleaseCooldown");
        h.Add("oncomplete", "OnTweenCompleteCometReleaseCooldown");
        iTween.ValueTo(gameObject, h);

        if (OnLandedOntoComet != null)
        {
            OnLandedOntoComet(this);
        }
    }
    public void PullInRope()
    {
        if (!ropeConnectedToPlayer && kunai.isStuck && kunai.ropeIntact)
        {
            ConnectRopeToPlayer();
        }

        SpringJoint2D playersJoint = GetComponent <SpringJoint2D>();
        Rigidbody2D   grapplePiece = playersJoint.connectedBody;
        Rigidbody2D   toDestroy;
        int           pulledIn = 1;

        if (grapplePiece == null)
        {
            grappleIsOut   = false;
            beingRetracted = false;
            return;
        }

        if ((grapplePiece.position - GetComponent <Rigidbody2D>().position).magnitude > ropeSegSize * pullInDistanceMultiplier)
        {
            return;
        }

        toDestroy = grapplePiece;
        if (kunai != null && grapplePiece == kunai.GetComponent <Rigidbody2D>())       //pulling in the kunai not a rope segment
        {
            pulledIn -= 2;
        }
        else
        {
            grapplePiece = grapplePiece.GetComponent <SpringJoint2D>().connectedBody;
        }
        toDestroy.GetComponent <NetworkView>().RPC("SelfDestruct", RPCMode.AllBuffered);
        //Destroy(toDestroy.gameObject);

        if (grapplePiece != null)
        {
            playersJoint.connectedBody = grapplePiece;
            lastRopeSegment            = grapplePiece.gameObject;
        }

        heldRopeSegments += pulledIn;
    }
    public static int set_distance(IntPtr l)
    {
        int result;

        try
        {
            SpringJoint2D springJoint2D = (SpringJoint2D)LuaObject.checkSelf(l);
            float         distance;
            LuaObject.checkType(l, 2, out distance);
            springJoint2D.distance = distance;
            LuaObject.pushValue(l, true);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
    public static int set_frequency(IntPtr l)
    {
        int result;

        try
        {
            SpringJoint2D springJoint2D = (SpringJoint2D)LuaObject.checkSelf(l);
            float         frequency;
            LuaObject.checkType(l, 2, out frequency);
            springJoint2D.frequency = frequency;
            LuaObject.pushValue(l, true);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Exemple #28
0
    /// <summary>
    /// Attach a spring to the other object
    /// </summary>
    /// <param name="other">Object to connect to</param>
    public void AttachSpringTo(GameObject other)
    {
        // Not if it's already connected
        if (IsConnected(other))
        {
            //Debug.Log("Already connected to " + other.name);
        }
        else
        {
            // Create the spring
            SpringJoint2D springJoint = gameObject.AddComponent <SpringJoint2D>();
            springJoint.distance = this.SpringDistance;
            springJoint.autoConfigureDistance = false;
            springJoint.connectedBody         = other.GetComponent <Rigidbody2D>();
            springJoint.anchor          = new Vector2(transform.localScale.x / 2, 0);
            springJoint.connectedAnchor = new Vector2(other.transform.localScale.x / 2, 0);;

            // Line Renderer
            var lineRenderer = gameObject.AddComponent <LineRenderer>();
            if (lineRenderer != null)
            {
                lineRenderer.endWidth = lineRenderer.startWidth = .05f;
            }

            // Add to the list of connections
            this.Connections.Add(new ParticleConnection
            {
                OtherGameObject = other,
                Spring          = springJoint,
                LineRenderer    = lineRenderer
            });

            // Once connected with the uranium, remove wind
            //if (this.tag == "Uranium")
            //{
            var wind = other.GetComponent <Scr_CarbonWind>();
            if (wind != null)
            {
                wind.enabled = false;
            }
            //}
        }
    }
Exemple #29
0
    public void Start()
    {
        this.col                = GetComponent <EdgeCollider2D>();
        this.vertices           = col.points;
        this.dJoint             = GetComponent <DistanceJoint2D>();
        this.sJoint             = GetComponent <SpringJoint2D>();
        this.rend               = GetComponent <LineRenderer>();
        this.rend.positionCount = 2;

        this.dJoint.connectedBody = this.startPoint.GetComponent <Rigidbody2D>();
        this.sJoint.connectedBody = this.endPoint.GetComponent <Rigidbody2D>();

        this.rend.SetPosition(0, this.startPoint.transform.position);
        this.rend.SetPosition(1, this.endPoint.transform.position);

        // this.rend.enabled = false;
        //this.gameObject.SetActive(false);
        // this.ConnectRope(this.startPoint, this.endPoint);
    }
Exemple #30
0
    private IEnumerator Release(float time)
    {
        currentBird.Release();
        yield return(new WaitForSeconds(time));

        springJoint.enabled = false;
        releasedBird        = currentBird;

        //this.enabled = false;
        yield return(new WaitForSeconds(1f));

        if (index < birds.Length)
        {
            currentBird = birds[index++];
            currentBird.transform.position = anchor.position;
            rb          = currentBird.RB;
            springJoint = currentBird.SpringJoint;
        }
    }