Пример #1
0
    private void DoStunMovement()
    {
        StunInformation info = stateManager.CurrentStateInformation_Exn <StunInformation>();

        StopAllMovementCoroutines(false);

        // If we for some reason transition to the stun state *after*
        // we were supposed to have finished with the stun state, just put
        // the player where they would have ended up
        float timeTravelledSoFar = (float)(PhotonNetwork.Time - info.EventTimeStamp);

        if (timeTravelledSoFar > info.Duration)
        {
            timeTravelledSoFar = info.Duration;
        }

        // Calculate the start position based on the time that has elapsed since
        // the message was sent
        rb2d.position = info.StartPosition + timeTravelledSoFar * info.Velocity;
        rb2d.velocity = info.Velocity;
    }
    private void HandleNewPlayerState(State oldState, State newState)
    {
        if (newState == State.Possession)
        {
            StartRumble(duration: ballPossessionRumbleDuration);
        }

        if (newState == State.Stun)
        {
            StunInformation info = stateManager.CurrentStateInformation_Exn <StunInformation>();
            if (info.StolenFrom)
            {
                StartRumble(duration: stealRumbleDuration);
            }
        }
    }
Пример #3
0
    /// <summary>
    /// Manages the duration of the stun.
    /// NOTE: Does not handle the movement. PlayerMovement will take care of managing
    /// that while in the stun state
    /// </summary>
    /// <returns></returns>
    private IEnumerator Stun()
    {
        StunInformation info = playerStateManager.CurrentStateInformation_Exn <StunInformation>();

        if (info.StolenFrom)
        {
            GameManager.NotificationManager.NotifyMessage(Message.BallWasStolen, this);
        }

        float timeSinceCall = (float)(PhotonNetwork.Time - info.EventTimeStamp);

        if (timeSinceCall < info.Duration)
        {
            yield return(new WaitForSeconds(info.Duration - timeSinceCall));
        }
        else
        {
            Debug.LogError("Entered stun after Duration. This shouldn't happen or should happen very rarely. Look into this");
        }

        playerStateManager.TransitionToState(State.NormalMovement);
    }
Пример #4
0
    private IEnumerator Dash()
    {
        DashInformation information = stateManager.CurrentStateInformation_Exn <DashInformation>();

        // TODO dkonik: Revisit this math, why do we do this?
        float dashDuration = Mathf.Min((information.Velocity.magnitude / dashSpeed) - 1f, 0.5f);

        AudioManager.instance.DashSound.Play();


        // Set duration of particle system for each dash trail.
        // TODO dkonik: Do not instantiate every time
        dashEffect = Instantiate(dashEffectPrefab, playerMovement.CurrentPosition, playerMovement.CurrentRotation, transform);

        foreach (ParticleSystem ps in dashEffect.GetComponentsInChildren <ParticleSystem>())
        {
            ps.Stop();
            ParticleSystem.MainModule main = ps.main;
            main.duration = dashDuration;
            ps.Play();
        }

        float startTime = Time.time;

        while (Time.time - startTime <= dashDuration)
        {
            yield return(null);
        }

        foreach (ParticleSystem ps in dashEffect.GetComponentsInChildren <ParticleSystem>())
        {
            ps.Stop();
        }

        stateManager.TransitionToState(State.NormalMovement);
    }