Ejemplo n.º 1
0
 public void CancelDrawing()
 {
     if (ropeCreator != null)
     {
         drawing = false;
         Destroy(ropeCreator.gameObject);
         ropeCreator = null;
     }
 }
Ejemplo n.º 2
0
    public void HandleInput(bool left, bool right, int drawRope, bool stopDraw)
    {
        float acc = 2000f * Time.deltaTime;

        if (left)
        {
            body.AddForce(new Vector2(-acc, 0f));
        }
        if (right)
        {
            body.AddForce(new Vector2(acc, 0f));
        }

        // Start drawing
        if (drawRope != -1 && !drawing)
        {
            ropeCreator = Instantiate(ropeTypes[drawRope], muzzle.position, Quaternion.identity);
            if (paint >= ropeCreator.initialPaintCost)
            {
                ropeCreator.SetupRopeCreator(muzzle.position.x, this);
                ropeCreator.index = ropesCreated;
                ropesCreated++;
                drawing = true;
            }
            else
            {
                CancelDrawing();
            }
        }
        // Release rope
        else if (stopDraw && ropeCreator != null)
        {
            ropeCreator.CreateRope();
            ropeCreator = null;
            drawing     = false;
        }
    }
Ejemplo n.º 3
0
 void OnEnable()
 {
     rope = target as RopeCreator;
 }
    private void FixedUpdate()
    {
        //OLD VERSION: Snap to position and rotation of the rope segment.
        //Visible snapping and rotation changes; Changed for a smooth lerp coroutine approach

        /*if (GetComponent<PlayerControlor>().right)
         *  transform.localEulerAngles = new Vector3(0, 0, 0);
         * else if (GetComponent<PlayerControlor>().right)
         *  transform.localEulerAngles = new Vector3(0, 180, 0);*/

        /*Vector3 p = transform.localPosition;
         * p.x = xOffset;
         * transform.localPosition = p;*/

        //Smoothly adapting position and rotation when character collider hits a segment rope collider
        if (!isOffsetting)
        {
            StartCoroutine(SetOffset(xOffset, 0.2f));
        }

        if (!isRotating)
        {
            StartCoroutine(SetRotation(GetComponent <PlayerControlor>().right, 0.7f));
        }


        //Raw and Smooth Inputs;
        var rawVerticalAxis    = Input.GetAxisRaw("Vertical");
        var smoothVerticalAxis = Input.GetAxis("Vertical");

        var smoothHorizontalAxis = Controls.horizontal;

        //While swinging on the rope, do not allow the player go move vertically;
        if (smoothHorizontalAxis != 0)
        {
            rawVerticalAxis    = 0;
            smoothVerticalAxis = 0;
        }

        //VERTICAL MOVEMENT
        //Setting switches and changing animation accordingly via Animator
        if (smoothVerticalAxis > 0.1)
        {
            //Climbing up
            if (!lastRopeSegment)
            {
                animator.SetBool("climbup", true);
                animator.SetBool("climbidle", false);
            }
            else
            {
                animator.SetBool("climbup", false);
                animator.SetBool("climbidle", true);
            }
            climbingSwitch = 1;
            slippingSwitch = 0;
        }
        else if (smoothVerticalAxis < -0.1)
        {
            //Sliding down
            climbingSwitch = 0;
            slippingSwitch = 1;
        }
        else
        {
            //Hanging Still
            animator.SetBool("climbup", false);
            animator.SetBool("climbidle", true);
            climbingSwitch = 0;
            slippingSwitch = 0;
        }

        //Move Vertically
        if (rawVerticalAxis != 0 || (smoothVerticalAxis < 0 && slipsDownABit) || (smoothVerticalAxis > 0 && slipsUpABit))
        {
            //Don't allow the character to go any higher than a certain rope segment (configurable per Rope in Rope Class)
            if (!lastRopeSegment || (lastRopeSegment && rawVerticalAxis < 0))
            {
                transform.Translate(Vector3.up * Mathf.Pow(climbingSpeed * smoothVerticalAxis, climbingSwitch) * Mathf.Pow(slippingSpeed * smoothVerticalAxis, slippingSwitch) * Time.deltaTime);
            }
        }


        //VERTICAL MOVEMENT
        if (smoothHorizontalAxis != 0 && canMoveHorizontally)
        {
            //Add force to the segment to which the character is attached;
            parentRopeSegment = transform.parent.gameObject;
            parentRopeSegment.GetComponent <Rigidbody2D>().AddRelativeForce(Vector3.right * horizontalSpeed * smoothHorizontalAxis);

            //All segments are numbered 0 - MaxSegmentNo
            int         result      = int.Parse(parentRopeSegment.name);
            GameObject  parentRope  = transform.parent.parentRopeSegment;
            string      ropeparent  = parentRope.name;
            RopeCreator ropeCreator = parentRope.GetComponent <RopeCreator>();

            Rope ropeSegment = parentRopeSegment.GetComponent <Rope>();

            //Double Checking that Rope was created with a RopeCreator
            //Add a smaller force to both closest segments to better simulate a continous object being pushed
            //Some segments may be deactivated through RopeCreator through ropeGrappleFactor - See RopeCreator.cs
            if (ropeCreator != null)
            {
                if (ropeSegment.segmentNumber != 1)
                {
                    GameObject.Find(ropeparent + "/" + (result - ropeCreator.ropeGrappleFactor).ToString()).GetComponent <Rigidbody2D>().AddRelativeForce(Vector3.right * horizontalSpeed / 2 * smoothHorizontalAxis);
                }
                if (!ropeSegment.lastRopeSegment)
                {
                    GameObject.Find(ropeparent + "/" + (result + ropeCreator.ropeGrappleFactor).ToString()).GetComponent <Rigidbody2D>().AddRelativeForce(Vector3.right * horizontalSpeed / 2 * smoothHorizontalAxis);
                }
            }
        }

        //Add Swinging Animations via Animator
        if ((smoothHorizontalAxis > 0 && playerControlor.right) ||
            (smoothHorizontalAxis < 0 && !playerControlor.right))
        {
            animator.SetInteger("swing", 1);
        }

        else if ((smoothHorizontalAxis < 0 && playerControlor.right) ||
                 (smoothHorizontalAxis > 0 && !playerControlor.right))
        {
            animator.SetInteger("swing", 0);
        }

        else
        {
            animator.SetInteger("swing", 0);
        }

        //Shake
        if (canShakeCarrier)
        {
            parentRopeSegment.GetComponent <Rigidbody2D>().AddRelativeForce(Vector3.right * smoothHorizontalAxis * 10);
        }

        if (rawHorizontalAxis != 0)
        {
            directionToFace = rawHorizontalAxis;
        }
    }