Пример #1
0
    private void Uncrinkle()
    {
        foreach (GameObject obj in _joints)
        {
            DestroyImmediate(obj);
        }
        _joints.Clear();
        InitializeBody(true);
        CameraPlayerController camera = FindObjectOfType <CameraPlayerController>();

        camera.mainPlayer = _joints[jointCount / 2].gameObject;
    }
Пример #2
0
    // Use this for initialization
    private void Start()
    {
        cameraPlayerController = Camera.main.gameObject.GetComponent <CameraPlayerController>();
        leftSpriteOff          = Resources.Load <Sprite>("Textures/leftButtonOff");
        rightSpriteOff         = Resources.Load <Sprite>("Textures/rightButtonOff");
        leftSpriteOn           = Resources.Load <Sprite>("Textures/leftButtonOn");
        rightSpriteOn          = Resources.Load <Sprite>("Textures/rightButtonOn");
        leftSpriteReady        = Resources.Load <Sprite>("Textures/leftButtonReady");
        rightSpriteReady       = Resources.Load <Sprite>("Textures/rightButtonReady");

        staticPhysicsLayer    = LayerMask.NameToLayer("Default");
        grabbablePhysicsLayer = LayerMask.NameToLayer("Grabbable");

        _radius       = width / 2f;
        _lineRenderer = GetComponent <LineRenderer>();
        _offsetVector = new Vector3(0f, labelOffset, -2f);
        InitializeBody();
    }
Пример #3
0
    // used to build out the physics body and joints of papermate
    private void InitializeBody(bool unCrinkle = false)
    {
        Rigidbody2D prevBody = null;

        _joints = new List <GameObject>();

        float   segLen   = paperLength / (float)jointCount;
        Vector3 spawnLoc = unCrinkle ? movingSpawn : transform.position;

        for (int i = 0; i < jointCount; i++)
        {
            GameObject joint          = new GameObject("joint_" + i);
            Transform  jointTransform = joint.transform;
            jointTransform.localPosition = spawnLoc + new Vector3(0, segLen * i, 0);

            joint.layer = LayerMask.NameToLayer("Nonattachable");
            jointTransform.SetParent(transform);
            joint.AddComponent <WinTrigger>();

            CapsuleCollider2D capsuleCollider = joint.AddComponent <CapsuleCollider2D>();
            capsuleCollider.size = new Vector2(0.21f, 0.6f);

            Rigidbody2D body = joint.AddComponent <Rigidbody2D>();
            body.collisionDetectionMode = CollisionDetectionMode2D.Continuous;
            body.interpolation          = RigidbodyInterpolation2D.Interpolate;

            //first joint
            if (prevBody != null)
            {
                // WILL: HIS IS THE OLD JOINT CODE. I REMOVED THIS AFTER CHANGING THE VEL AND POS ITERATIONS
                // joint.AddComponent<DistanceJoint2D>().connectedBody = prevBody;
                // HingeJoint2D hinge = joint.AddComponent<HingeJoint2D>();
                // hinge.useLimits = true;
                // hinge.connectedBody = prevBody;
                // JointAngleLimits2D limits = new JointAngleLimits2D();
                // limits.max = 0;
                // limits.min = 0;
                // hinge.limits = limits;
                // body.mass = 0.5f;

                // WILL: NEW SIMPLE JOINT CODE
                FixedJoint2D hinge = joint.AddComponent <FixedJoint2D>();
                hinge.connectedBody = prevBody;
                body.mass           = 0.5f;
            }

            _joints.Add(joint);
            prevBody = body;

            // Add colliders on the ends for latching onto objects
            if (i == 0)
            {
                leftCollider           = joint.AddComponent <CircleCollider2D>();
                leftCollider.radius    = _radius * 2f;
                leftCollider.isTrigger = true;
                body.mass = 10f;
                capsuleCollider.offset = new Vector2(0, 0.1f);
                capsuleCollider.size   = new Vector2(0.21f, 0.21f);
            }
            if (i == jointCount - 1)
            {
                rightCollider           = joint.AddComponent <CircleCollider2D>();
                rightCollider.radius    = _radius * 2f;
                rightCollider.isTrigger = true;
                body.mass = 10f;
                capsuleCollider.offset = new Vector2(0, -0.1f);
                capsuleCollider.size   = new Vector2(0.21f, 0.21f);
            }
        }

        // use world points and set up for three points per joint minus the two dangling off the ends
        _lineRenderer.useWorldSpace = true;
        _lineRenderer.positionCount = jointCount;
        UpdateLineRendererPositions();

        // set the middle point as the camera follower
        CameraPlayerController camera = FindObjectOfType <CameraPlayerController>();

        camera.mainPlayer = _joints[jointCount / 2].gameObject;

        transform.SetParent(_joints[jointCount / 2].gameObject.transform);

        InitializeStabilizers(_joints.First().GetComponent <Rigidbody2D>(), _joints.Last().GetComponent <Rigidbody2D>());
    }
Пример #4
0
 void Start()
 {
     _cpc = Camera.main.gameObject.GetComponent <CameraPlayerController>();
 }
Пример #5
0
    // used to build out the physics body and joints of papermate
    private void InitializeBody(bool unCrinkle = false)
    {
        Rigidbody2D prevBody = null;

        _joints = new List <GameObject>();

        float   segLen   = paperLength / (float)jointCount;
        Vector3 spawnLoc = unCrinkle ? movingSpawn : transform.position;

        for (int i = 0; i < jointCount; i++)
        {
            GameObject joint          = new GameObject("joint_" + i);
            Transform  jointTransform = joint.transform;
            jointTransform.localPosition = spawnLoc + new Vector3(0, segLen * i, 0);

            joint.layer = LayerMask.NameToLayer("Nonattachable");
            jointTransform.SetParent(transform);
            joint.AddComponent <WinTrigger>();

            Rigidbody2D body = joint.AddComponent <Rigidbody2D>();
            body.collisionDetectionMode = CollisionDetectionMode2D.Continuous;
            body.interpolation          = RigidbodyInterpolation2D.Interpolate;

            // Add colliders on the ends for latching onto objects
            CapsuleCollider2D collider = joint.AddComponent <CapsuleCollider2D>();
            collider.size = new Vector2(0.21f, segLen);

            if (i == 0)
            {
                leftCollider           = joint.AddComponent <CircleCollider2D>();
                leftCollider.radius    = segLen * 0.75f;
                leftCollider.isTrigger = true;
                body.mass = 10f;
            }
            else if (i == jointCount - 1)
            {
                rightCollider           = joint.AddComponent <CircleCollider2D>();
                rightCollider.radius    = segLen / 2;
                rightCollider.isTrigger = true;
                body.mass = 10f;

                HingeJoint2D hinge = joint.AddComponent <HingeJoint2D>();
                hinge.connectedBody = prevBody;
            }
            else
            {
                HingeJoint2D hinge = joint.AddComponent <HingeJoint2D>();
                hinge.connectedBody = prevBody;
            }

            _joints.Add(joint);
            prevBody = body;
        }

        // use world points and set up for three points per joint minus the two dangling off the ends
        _lineRenderer.useWorldSpace = true;
        _lineRenderer.positionCount = jointCount;
        UpdateLineRendererPositions();

        // set the middle point as the camera follower
        CameraPlayerController camera = FindObjectOfType <CameraPlayerController>();

        camera.mainPlayer = _joints[jointCount / 2].gameObject;

        transform.SetParent(_joints[jointCount / 2].gameObject.transform);

        //InitializeStabilizers(_joints.First().GetComponent<Rigidbody2D>(), _joints.Last().GetComponent<Rigidbody2D>());
    }