Ejemplo n.º 1
0
    void Update()
    {
        float screechAmount = 0;
        bool allPopped = true;
        bool nonePopped = true;
        float alwaysScrape = 0;

        for (int i = 0; i < vp.wheels.Length; i++)
        {
            if (wheels[i].connected)
            {
                if (Mathf.Abs(F.MaxAbs(wheels[i].sidewaysSlip, wheels[i].forwardSlip, alwaysScrape)) - slipThreshold > 0)
                {
                    if (wheels[i].popped)
                    {
                        nonePopped = false;
                    }
                    else
                    {
                        allPopped = false;
                    }
                }

                if (wheels[i].grounded)
                {
                    surfaceType = GroundSurfaceMaster.surfaceTypesStatic[wheels[i].contactPoint.surfaceType];

                    if (surfaceType.alwaysScrape)
                    {
                        alwaysScrape = slipThreshold + Mathf.Min(0.5f, Mathf.Abs(wheels[i].rawRPM * 0.001f));
                    }
                }

                screechAmount = Mathf.Max(screechAmount, F.PowNatural(Mathf.Clamp01(Mathf.Abs(F.MaxAbs(wheels[i].sidewaysSlip, wheels[i].forwardSlip, alwaysScrape)) - slipThreshold), 2));
            }
        }

        //Set audio clip based on number of wheels popped
        if (surfaceType != null)
        {
            snd.clip = allPopped ? surfaceType.rimSnd : (nonePopped ? surfaceType.tireSnd : surfaceType.tireRimSnd);
        }

        //Set sound volume and pitch
        if (screechAmount > 0)
        {
            if (!snd.isPlaying)
            {
                snd.Play();
                snd.volume = 0;
            }
            else
            {
                snd.volume = Mathf.Lerp(snd.volume, screechAmount * ((vp.groundedWheels * 1.0f) / (wheels.Length * 1.0f)), 2 * Time.deltaTime);
                snd.pitch = Mathf.Lerp(snd.pitch, 0.5f + screechAmount * 0.9f, 2 * Time.deltaTime);
            }
        }
        else if (snd.isPlaying)
        {
            snd.volume = 0;
            snd.Stop();
        }
    }
Ejemplo n.º 2
0
    private void GameLoop()
    {
        RaycastHit hit;

        _isGrounded = Physics.Raycast(transform.position, Vector3.down, out hit, _groundedThreshold, _groundLayer);

        if (hit.collider != null && (InputManager.Instance.MoveDir1 != Vector3.zero || InputManager.Instance.MoveDir2 != Vector3.zero))
        {
            GroundSurface surface = hit.collider.GetComponent <GroundSurface>();
            if (surface != null)
            {
                AudioManager.Instance.PlayStepSound(surface.StepSurface);
            }
        }

        if (_isFire)
        {
            _transTimeStamp += Time.deltaTime;

            if (_transTimeStamp >= _transDuration)
            {
                _isFire          = false;
                _transTimeStamp  = 0;
                gameObject.layer = 9;
                _fireSphere.SetActive(false);
            }
        }

        if (_isWater)
        {
            _transTimeStamp += Time.deltaTime;

            if (_transTimeStamp >= _transDuration)
            {
                _isWater         = false;
                _transTimeStamp  = 0;
                gameObject.layer = 9;
                _waterSphere.SetActive(false);
            }
        }

        // Debug.Log(_isGrounded + gameObject.name);

        if (_isPlayerOne)
        {
            _moveDir = InputManager.Instance.MoveDir1;
            if (_moveDir.x > 0)
            {
                transform.forward = Vector3.forward;
            }
            if (_moveDir.x < 0)
            {
                transform.forward = Vector3.back;
            }
        }
        else
        {
            _moveDir = InputManager.Instance.MoveDir2;
            if (_moveDir.x > 0)
            {
                transform.forward = Vector3.forward;
            }
            if (_moveDir.x < 0)
            {
                transform.forward = Vector3.back;
            }
        }

        //dans un ontrigger enter elem contraire ; si je suis dans mon elem : change state steam

        /*if(Input.GetKeyDown(KeyCode.Space))
         *  {
         *      TransformToSteam();
         *  }*/
    }
Ejemplo n.º 3
0
    void Update()
    {
        float screechAmount = 0;
        bool  allPopped     = true;
        bool  nonePopped    = true;
        float alwaysScrape  = 0;

        for (int i = 0; i < vp.wheels.Length; i++)
        {
            if (wheels[i].connected)
            {
                if (Mathf.Abs(F.MaxAbs(wheels[i].sidewaysSlip, wheels[i].forwardSlip, alwaysScrape)) - slipThreshold > 0)
                {
                    if (wheels[i].popped)
                    {
                        nonePopped = false;
                    }
                    else
                    {
                        allPopped = false;
                    }
                }

                if (wheels[i].grounded)
                {
                    surfaceType = GroundSurfaceMaster.surfaceTypesStatic[wheels[i].contactPoint.surfaceType];

                    if (surfaceType.alwaysScrape)
                    {
                        alwaysScrape = slipThreshold + Mathf.Min(0.5f, Mathf.Abs(wheels[i].rawRPM * 0.001f));
                    }
                }

                screechAmount = Mathf.Max(screechAmount, Mathf.Pow(Mathf.Clamp01(Mathf.Abs(F.MaxAbs(wheels[i].sidewaysSlip, wheels[i].forwardSlip, alwaysScrape)) - slipThreshold), 2));
            }
        }

        //Set audio clip based on number of wheels popped
        if (surfaceType != null)
        {
            snd.clip = allPopped ? surfaceType.rimSnd : (nonePopped ? surfaceType.tireSnd : surfaceType.tireRimSnd);
        }

        //Set sound volume and pitch
        if (screechAmount > 0)
        {
            if (!snd.isPlaying)
            {
                snd.Play();
                snd.volume = 0;
            }
            else
            {
                snd.volume = Mathf.Lerp(snd.volume, screechAmount * ((vp.groundedWheels * 1.0f) / (wheels.Length * 1.0f)), 2 * Time.deltaTime);
                snd.pitch  = Mathf.Lerp(snd.pitch, 0.5f + screechAmount * 0.9f, 2 * Time.deltaTime);
            }
        }
        else if (snd.isPlaying)
        {
            snd.volume = 0;
            snd.Stop();
        }
    }