private void Update()
        {
            if (UI.PauseMenu.GamePaused)
            {
                return;                                       //Short circuit if paused
            }
            //GO FAST
            const float weight = 0.5f;

            Vector3 targetVector = GameInput.MovementVector(ball.CtrlType);

            rawDirection = Vector3.MoveTowards(rawDirection, targetVector, weight);
            Vector3 directionVector = rawDirection;

            if (directionVector != Vector3.zero)
            {
                //Modify direction vector to be more controller-friendly (And normalize it)
                var directionLength = directionVector.magnitude;
                directionVector = directionVector / directionLength;
                directionLength = Mathf.Min(1, directionLength);
                directionLength = directionLength * directionLength;
                directionVector = directionVector * directionLength;
            }
            directionVector      = LookDirection * Quaternion.Euler(0f, 90f, 0) * directionVector; //Multiply vector by camera rotation
            ball.DirectionVector = directionVector;

            //BRAKE FAST
            ball.Brake = GameInput.IsBraking(ball.CtrlType);

            //JUMP FAST
            if (GameInput.IsJumping(ball.CtrlType))
            {
                if (!hasJumped)
                {
                    ball.Jump();
                    hasJumped = true;
                }
            }
            else
            {
                if (hasJumped)
                {
                    hasJumped = false;
                }
            }

            //RESPAWN FAST
            if (GameInput.IsRespawning(ball.CtrlType) && ball.CanMove)
            {
                ball.RequestRespawn();
            }

            //Switch Camera Fast
            if (GameInput.IsSwitchingCameras(ball.CtrlType) && ball.CanMove)
            {
                ball.SwitchCameraBall();
            }
        }
Ejemplo n.º 2
0
        private void Update()
        {
            if (type == BallType.AI && isServer && !isClient)
            {
                //Rolling sounds
                if (grounded)
                {
                    float rollSpd = Mathf.Clamp(rb.angularVelocity.magnitude / 230, 0, 16);
                    float vel     = (-128f + rb.velocity.magnitude) / 256;                 //Start at 128 fph, end at 256

                    vel = Mathf.Clamp(vel, 0, 1);
                    if (sounds.Roll != null)
                    {
                        sounds.Roll.pitch  = Mathf.Max(rollSpd, 0.8f);
                        sounds.Roll.volume = Mathf.Min(rollSpd, 1);
                    }
                    if (sounds.SpeedNoise != null)
                    {
                        sounds.SpeedNoise.pitch  = 0.8f + vel;
                        sounds.SpeedNoise.volume = vel;
                    }
                }
                else
                {
                    //Fade sounds out when in the air
                    if (sounds.Roll != null && sounds.Roll.volume > 0)
                    {
                        sounds.Roll.volume = Mathf.Max(0, sounds.Roll.volume - 0.2f);
                    }
                    if (sounds.SpeedNoise != null && sounds.SpeedNoise.volume > 0)
                    {
                        sounds.SpeedNoise.volume = Mathf.Max(0, sounds.SpeedNoise.volume - 0.01f);
                    }
                }

                //Grounded timer
                if (groundedTimer > 0)
                {
                    groundedTimer = Mathf.Max(0, groundedTimer - Time.deltaTime);
                    if (groundedTimer <= 0)
                    {
                        grounded = false;
                        Up       = Vector3.up;
                    }
                }

                //Smoke
                if (smoke != null)
                {
                    smoke.grounded = grounded;
                }
            }

            if (!isLocalPlayer)
            {
                return;
            }

            if (GameInput.IsRespawning(ctrlType))
            {
                if (NetworkManager.singleton.GetComponent <SanicNetworkManager>().isSpawning != true)
                {
                    if (!isServer)
                    {
                        CmdToggleReady(Sanicball.Data.ActiveData.GameSettings.nickname);



                        LobbyReferences.Active.CountdownField.enabled = true;
                        LobbyReferences.Active.CountdownField.text    = "Wait Until the Race Begin...";
                    }
                    else
                    {
                        Debug.Log("Ready ?? + " + isServer);

                        if (NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager != null && (NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager.serverConnections + 1) > 1)
                        {
                            //				for( int i =0 ; i< NetworkServer.connections.Count; i ++  ){
                            for (int i = 0; i < NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager.Players.Count; i++)
                            {
                                if (this.connectionToClient.connectionId == NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager.Players[i].ConnectionSelf.connectionId)
                                {
                                    NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager.Players[i].ReadyToRace = !NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager.Players[i].ReadyToRace;

                                    if (NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager.Players[i].ReadyToRace)
                                    {
                                        ChatRelayer.Instance.SetLogMessage(Sanicball.Data.ActiveData.GameSettings.nickname + " is READY to RACE");
                                    }
                                    else
                                    {
                                        ChatRelayer.Instance.SetLogMessage(Sanicball.Data.ActiveData.GameSettings.nickname + " is NOT READY to RACE");
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (this.CanMove)
                    {
                        if (isServer)
                        {
                            this.RequestRespawn();
                        }
                        else
                        {
                            CmdRequestSpawn(currentCheckPoin, netId);
                        }
                    }
                }
            }

            //Rolling sounds
            if (grounded)
            {
                float rollSpd = Mathf.Clamp(rb.angularVelocity.magnitude / 230, 0, 16);
                float vel     = (-128f + rb.velocity.magnitude) / 256;     //Start at 128 fph, end at 256

                vel = Mathf.Clamp(vel, 0, 1);
                if (sounds.Roll != null)
                {
                    sounds.Roll.pitch  = Mathf.Max(rollSpd, 0.8f);
                    sounds.Roll.volume = Mathf.Min(rollSpd, 1);
                }
                if (sounds.SpeedNoise != null)
                {
                    sounds.SpeedNoise.pitch  = 0.8f + vel;
                    sounds.SpeedNoise.volume = vel;
                }
            }
            else
            {
                //Fade sounds out when in the air
                if (sounds.Roll != null && sounds.Roll.volume > 0)
                {
                    sounds.Roll.volume = Mathf.Max(0, sounds.Roll.volume - 0.2f);
                }
                if (sounds.SpeedNoise != null && sounds.SpeedNoise.volume > 0)
                {
                    sounds.SpeedNoise.volume = Mathf.Max(0, sounds.SpeedNoise.volume - 0.01f);
                }
            }

            //Grounded timer
            if (groundedTimer > 0)
            {
                groundedTimer = Mathf.Max(0, groundedTimer - Time.deltaTime);
                if (groundedTimer <= 0)
                {
                    grounded = false;
                    Up       = Vector3.up;
                }
            }

            //Smoke
            if (smoke != null)
            {
                smoke.grounded = grounded;
            }
        }