Ejemplo n.º 1
0
    private void StartGrind(GrindRail rail, bool playSound)
    {
        currentRail = rail;
        Active      = true;
        if (playSound)
        {
            AudioManager.Instance.PlaySoundVaried("GrindStart");
        }

        // Snap player to rail
        transform.position = currentRail.ClosestPointOnRail(transform.position);

        Vector3 railDir = currentRail.GetForward();
        float   dot     = DotWithRail(transform.forward, currentRail);

        // Player should go forward on the rail
        if (dot >= 0.0f)
        {
            transform.rotation = Quaternion.LookRotation(railDir, currentRail.GetNormal());
        }
        // Player should go backwards on the rail
        else
        {
            transform.rotation = Quaternion.LookRotation(-railDir, currentRail.GetNormal());
        }
    }
Ejemplo n.º 2
0
    public void StopGrind(bool playSound)
    {
        Active = false;

        if (playSound)
        {
            AudioManager.Instance.PlaySoundVaried("GrindEnd");
        }

        currentRail = null;
    }
Ejemplo n.º 3
0
    public void TryGrind()
    {
        if (grindRails.Count <= 0)
        {
            return;
        }

        GrindRail closest = FindClosestRail();

        Debug.Assert(closest != null, "ERROR: Couldn't find a closest grind rail");

        if (closest.CanGrind(transform.position))
        {
            StartGrind(closest, true);
        }

        return;
    }
Ejemplo n.º 4
0
    public override void OnMove(float steering, float accelInput, bool isGrounded, float boostInput)
    {
        if (!Active)
        {
            return;
        }

        // Check if fallen off end of rail
        if ((currentRail.ClosestPointOnRail(transform.position) - transform.position).magnitude > fallenOffDistance)
        {
            // First, try to find another rail to snap to
            GrindRail closest = FindClosestRail();

            float closestDot = Vector3.Dot(closest.GetForward(), rigidBody.velocity.normalized);

            if (Mathf.Abs(closestDot) > 0.75f && closest.CanGrind(transform.position))
            {
                StopGrind(false);
                StartGrind(closest, true);
            }
            else
            {
                StopGrind(true);
            }

            return;
        }

        // If not, align player velocity with rail
        float dot = DotWithRail(rigidBody.velocity.normalized, currentRail);

        Vector3 railDir = currentRail.GetForward();

        // Player should go forward on the rail
        if (dot >= 0.0f)
        {
            rigidBody.velocity = rigidBody.velocity.magnitude * railDir;
        }
        else
        {
            rigidBody.velocity = rigidBody.velocity.magnitude * -railDir;
        }
    }
Ejemplo n.º 5
0
    private GrindRail FindClosestRail()
    {
        GrindRail closest     = null;
        float     closestDist = 999999.0f;

        for (int i = 0; i < grindRails.Count; i++)
        {
            GrindRail testRail = grindRails[i];
            if (currentRail && testRail.GetInstanceID() == currentRail.GetInstanceID())
            {
                continue;
            }

            float dist = (testRail.ClosestPointOnRail(transform.position) - transform.position).magnitude;

            if (dist < closestDist)
            {
                closest     = testRail;
                closestDist = dist;
            }
        }

        return(closest);
    }
Ejemplo n.º 6
0
    private float DotWithRail(Vector3 other, GrindRail rail)
    {
        Vector3 railDir = rail.GetForward();

        return(Vector3.Dot(other, railDir));
    }