Beispiel #1
0
    //Check if there are any available platforms to swing from
    void CheckForSwingablePlatform()
    {
        //Get the rope's start position (offset by y + 0.5f)
        ropeStartPosition = transform.position;
        ropeStartPosition.y += 0.5f;

        //Check through each possible platform
        for(int i = 0; i < arrPlatform.Length; ++i)
        {
            //Get the length of the vector from the player to the current platform
            lineToPlatform = arrPlatform[i].transform.position - ropeStartPosition;
            lineToPlatformLength = lineToPlatform.magnitude;
        //	lineToPlatformLength = Vector3.Distance(arrPlatform[i].transform.position, ropeStartPosition);

            //Check if the player is close enough and below the platform
            if(lineToPlatformLength <= minSwingDistance && ropeStartPosition.y < arrPlatform[i].transform.position.y)
            {
                print("new rope established");
                //The player is now swinging
                isSwinging = true;//toggle

                //The rope has already been fired
                isShootingRope = false;

                //Establish new rope
                currentRope = new cCurrentRope();
                currentRope.thePlatform = arrPlatform[i];
                currentRope.start = ropeStartPosition;
                currentRope.end = currentRope.thePlatform.transform.position;
                currentRope.ropeVector = currentRope.start - currentRope.end;
                currentRope.currentLength = currentRope.ropeVector.magnitude;
                currentRope.savedLength = currentRope.currentLength;

                //Normalize the vector so we can apply our own rope tension
                currentRope.ropeVector.Normalize();

                break;	//There is only ever one platform to be attached to at a time, so break from the loop
            }
        }
    }
Beispiel #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        // If the player presses the shoot rope button
        if(Input.GetButtonDown("ShootRope"))
        {
            //If the player is currently swinging from a rope, then stop
            if(currentRope != null)
            {
                isSwinging = false;
                currentRope = null;
                print("let go from rope");
            }
            //else, the player is trying to latch onto a platform
            else
            {
                isShootingRope = true;
                print("shooting rope");
            }
        }
        // else the player is not shooting their rope
        else
        {
            isShootingRope = false;
        }

        //If the player is shooting their rope
        if(isShootingRope == true)
        {
            CheckForSwingablePlatform();
        }
        //If the player is swinging
        if(isSwinging)
        {
            ApplySwingForces();
        }
    }