Beispiel #1
0
 public void DetachRope(RopeBehavior rope)
 {
     body.drag = 0f;
     if (!isDead)
     {
         animator.SetTrigger("Unroped");
     }
 }
Beispiel #2
0
 public virtual void AttachRope(RopeBehavior rope)
 {
     rope.ropeHolder.spriteRenderer.size = new Vector2(0.15f, 0.03f);
     body.velocity = Vector2.zero;
     moveInput     = Vector2.zero;
     body.drag     = 100f;
     animator.SetTrigger("Roped");
     stateManager.EventRoped();
 }
Beispiel #3
0
 public virtual void DetachRope(RopeBehavior rope)
 {
     body.velocity = Vector2.zero;
     moveInput     = Vector2.zero;
     body.drag     = 0f;
     if (!isDead)
     {
         animator.SetTrigger("Unroped");
     }
 }
Beispiel #4
0
    void ApplyRopeAttach(GameObject ropedObject)
    {
        if (hero.rope != null)
        {
            return;
        }

        hero.animator.SetTrigger("RopeSuccess");
        RopeBehavior rope = Instantiate(ropePrefab).GetComponent <RopeBehavior> ();

        rope.InitializeRope(base.gameObject, ropedObject);
        Ropeable roped = ropedObject.GetComponent <Ropeable>();

        roped.AttachRope(rope);
    }
Beispiel #5
0
    IEnumerator DoRewind()
    {
        yield return(new WaitForSeconds(rewindDelay));

        yield return(new WaitForFixedUpdate()); // Ensure we're starting on a physics beat

        thePostProcessingBehaviour.enabled = true;
        theRewindUIPanel.gameObject.SetActive(true);

        IsRewinding = true;

        // Add the final state so we can begin to rewind:
        thePositionHistory.Add(new PositionHistory(thePlayerShip.transform, theSkier.transform, skierViewModelTransform, skiRopeJoint == null ? false : true));

        float rewindTime        = 0f;
        float rewindInterval    = saveInterval / rewindSpeed;
        float scaleFactor       = 1.0f;
        bool  hasReattachedRope = false;

        rewindTime = -Time.fixedDeltaTime; // Cancel out the first delta term so we start lerping at 0

        int currentPositionIndex = thePositionHistory.Count - 1;

        while (currentPositionIndex > 0)
        {
            rewindTime %= rewindInterval;

            while (rewindTime < rewindInterval)
            {
                rewindTime += (Time.fixedDeltaTime * scaleFactor);

                float lerpDelta = Mathf.Clamp01(rewindTime / rewindInterval);

                // Reset the ship:
                shipRigidbody.MovePosition(Vector3.Lerp(thePositionHistory[currentPositionIndex].shipPosition, thePositionHistory[currentPositionIndex - 1].shipPosition, lerpDelta));
                shipRigidbody.MoveRotation(Quaternion.Lerp(thePositionHistory[currentPositionIndex].shipRotation, thePositionHistory[currentPositionIndex - 1].shipRotation, lerpDelta));

                // Reset the skier:
                skierRigidbody.MovePosition(Vector3.Lerp(thePositionHistory[currentPositionIndex].skierPosition, thePositionHistory[currentPositionIndex - 1].skierPosition, lerpDelta));
                skierRigidbody.MoveRotation(Quaternion.Lerp(thePositionHistory[currentPositionIndex].skierRotation, thePositionHistory[currentPositionIndex - 1].skierRotation, lerpDelta));

                skierViewModelTransform.rotation = Quaternion.Lerp(thePositionHistory[currentPositionIndex].skierViewMeshRotation, thePositionHistory[currentPositionIndex - 1].skierViewMeshRotation, lerpDelta);

                // Reset the rope:
                if (thePositionHistory[currentPositionIndex].isConnected)
                {
                    if (!hasReattachedRope)
                    {
                        hasReattachedRope = true;

                        theRope.SetActive(true);
                        RopeBehavior theRopeController = theRope.GetComponent <RopeBehavior>();
                        theRopeController.skierRopeAttachPointTransform = theSkier.transform;

                        Transform[] shipChildTransforms = thePlayerShip.GetComponentsInChildren <Transform>();
                        foreach (Transform current in shipChildTransforms)
                        {
                            if (current.name == "PlayerShipRopeAttachPoint") // TO DO: Replace this with a (much faster) tag comparison
                            {
                                theRopeController.playerShipRopeAttachPointTransform = current;
                                break;
                            }
                        }
                    }
                    else
                    {
                        theRope.GetComponent <RopeBehavior>().Update(); // Manually force an update, to ensure the rope is correctly aligned
                    }
                }

                yield return(new WaitForFixedUpdate());
            } // End of inner "lerping" loop

            // Increase the rewind speed until half the points have been rewound, then decrease it again
            if (currentPositionIndex >= thePositionHistory.Count / 2)
            {
                scaleFactor += rewindSpeedIncreaseFactor;
            }
            else
            {
                scaleFactor -= rewindSpeedIncreaseFactor;
            }

            currentPositionIndex--;
        } // End of outer "positions" loop

        // Set the final ship position:
        shipRigidbody.MovePosition(thePositionHistory[0].shipPosition);
        shipRigidbody.MoveRotation(thePositionHistory[0].shipRotation);

        // Recreate the skier from its prefab for simpler joint setup:
        Destroy(theSkier.gameObject);
        theSkier = Instantiate <GameObject>(skierPrefab, thePositionHistory[0].skierPosition, thePositionHistory[0].skierRotation);
        theSkier.GetComponentInChildren <SkierAIController>().playerShipTransform = thePlayerShip.transform;

        Transform[] skierTransforms = theSkier.GetComponentsInChildren <Transform>();
        foreach (Transform current in skierTransforms)
        {
            if (current.gameObject.name == "ViewMesh")
            {
                skierViewModelTransform = current;
                break;
            }
        }
        skierViewModelTransform.rotation = thePositionHistory[0].skierViewMeshRotation;

        skierRigidbody = theSkier.GetComponent <Rigidbody>();

        skiRopeJoint = theSkier.GetComponent <ConfigurableJoint>();
        skiRopeJoint.autoConfigureConnectedAnchor = false; // This is required for the following 2 properties to stick
        skiRopeJoint.connectedAnchor = skiRopeConnectedAnchor;
        skiRopeJoint.anchor          = skiRopeAnchor;
        skiRopeJoint.connectedBody   = shipRigidbody;

        theRope.GetComponent <RopeBehavior>().skierRopeAttachPointTransform = theSkier.transform;
        theRope.GetComponent <RopeBehavior>().Update(); // Manually force an update, to ensure the rope is correctly aligned

        shipRigidbody.velocity  = Vector3.zero;
        skierRigidbody.velocity = Vector3.zero;

        thePositionHistory.Clear();
        thePositionHistory.Add(new PositionHistory(thePlayerShip.transform, theSkier.transform, skierViewModelTransform, skiRopeJoint == null ? false : true)); // Ensure the list is never empty, to avoid issues if the player immediately re-crashes

        thePostProcessingBehaviour.enabled = false;
        theRewindUIPanel.gameObject.SetActive(false);

        IsRewinding   = false;
        aboutToRewind = false;
    }
Beispiel #6
0
 public void AttachRope(RopeBehavior rope)
 {
     rope.ropeHolder.spriteRenderer.size = new Vector2(moveCollider.bounds.size.x, 0.04f);
     connectedRopes += 1;
 }
Beispiel #7
0
 public void DetachRope(RopeBehavior rope)
 {
     connectedRopes = Mathf.Max(0, connectedRopes - 1);
 }
Beispiel #8
0
 public void AttachRope(RopeBehavior rope)
 {
     rope.ropeHolder.spriteRenderer.size = new Vector2(0.15f, 0.03f);
     body.drag = 100f;
     animator.SetTrigger("Roped");
 }