Exemplo n.º 1
0
    void Update()
    {
        if (bodyIsBeingAttracted && lerpPct < 1 && isActive)
        {
            // interpolate the body from start to end.
            AttractedBody.transform.position = Vector3.Lerp(startPosition, end.position, lerpPct);
            AttractedBody.transform.rotation = Quaternion.Lerp(startRotation, end.rotation, lerpPct);

            // updating the position using a time scale.
            lerpPct += Time.deltaTime / transitionTime;
        }
        else
        {
            // enabling custom gravity once again.
            if (lerpPct >= 1 && AttractedBodyGravityScript)
            {
                AttractedBodyGravityScript.EnableVelocity(true);
                AttractedBodyGravityScript = null;
            }

            // reseting default values.
            lerpPct = 0;
            bodyIsBeingAttracted = false;
        }
    }
Exemplo n.º 2
0
    void OnTriggerEnter(Collider other)
    {
        if (!isActive)
        {
            return;
        }

        AttractedBody = other.gameObject;

        // computing the point nearest to the player.
        float nearA = (AttractedBody.transform.position - pointA.position).sqrMagnitude;
        float nearB = (AttractedBody.transform.position - pointB.position).sqrMagnitude;

        // the player will be teleported to the nearest point.
        // for the start pos we do not use a transform because if the player
        // transform is copied then the start point updates with the player position.
        startPosition = AttractedBody.transform.position;
        startRotation = AttractedBody.transform.rotation;
        end           = nearA > nearB ? pointA : pointB;

        // start lerping the player toward the other point.
        bodyIsBeingAttracted = true;

        // deactivate gravity script for the player.
        NPlayerController PlayerGravityScript = AttractedBody.GetComponent <NPlayerController>();

        if (PlayerGravityScript)
        {
            AttractedBodyGravityScript = PlayerGravityScript;
            AttractedBodyGravityScript.EnableVelocity(false);
        }
    }
Exemplo n.º 3
0
 public void SetPlayerVelocity(bool state)
 {
     controllerScript.EnableVelocity(state);
 }