AddForce() public method

public AddForce ( Vector3 positional, Vector3 angular ) : void
positional Vector3
angular Vector3
return void
    ///////////////////////////////////////////////////////////
    // NOTE: this should not be the logic governing a world-wide
    // quake. other objects may also need updating i.e. on the
    // server. rather, when your main game logic has determined
    // the amplitude and length of an earthquake, feed it to this
    // method to update this particular client. if you require
    // more exact positioning you may want to use another earth-
    // quake logic altogether.
    ///////////////////////////////////////////////////////////
    protected void UpdateEarthQuake()
    {
        if (m_EarthQuakeTime <= 0.0f)
        {
            return;
        }

        m_EarthQuakeTime -= 0.0166f * (60 * Time.deltaTime);             // reduce earthquake time by 1 every second

        if (!Controller.isGrounded)
        {
            return;
        }

        // the horisontal move is a perlin noise value between 0 and
        // 'm_EarthQuakeMagnitude' (depending on 'm_EarthQuakeTime').
        // horizMove will ease out during the last second.
        Vector3 horizMove = Vector3.Scale(vp_SmoothRandom.GetVector3Centered(1), new Vector3(m_EarthQuakeMagnitude.x,
                                                                                             0, m_EarthQuakeMagnitude.x)) * Mathf.Min(m_EarthQuakeTime, 1.0f);

        // the vertical move is half the earthquake magnitude and
        // has a 30% chance of occuring each frame. when it does,
        // it alternates between positive and negative. this produces
        // sharp shakes with nice spring smoothness inbetween.
        // vertMove will ease out during the last second.
        float vertMove = 0;

        if (UnityEngine.Random.value < 0.3f)
        {
            vertMove = UnityEngine.Random.Range(0, (m_EarthQuakeMagnitude.y * 0.35f)) * Mathf.Min(m_EarthQuakeTime, 1.0f);
            if (m_PositionSpring.State.y >= m_PositionSpring.RestState.y)
            {
                vertMove = -vertMove;
            }
        }

        // apply horisontal move to the camera spring.
        // NOTE: this will only shake the camera, though it will give
        // the appearance of pushing the player around.

        // TIP: for a more physical feel, apply the horisontal move to the
        // the controller's horisontal plane instead of the camera spring.
        // note however that this will have gameplay implications since
        // the character will now move in world space.
        // example: YourFPSController.AddForce(horizMove);
        m_PositionSpring.AddForce(horizMove);

        // apply earthquake roll force on the camera rotation spring
        m_RotationSpring.AddForce(new Vector3(0, 0, -horizMove.x * 2) * m_EarthQuakeCameraRollFactor);

        // apply earthquake force on the current weapon, if present
        if (m_CurrentWeapon != null)
        {
            m_CurrentWeapon.AddForce(new Vector3(0, 0, -horizMove.z * 0.015f) * m_EarthQuakeWeaponShakeFactor,
                                     new Vector3(vertMove * 2, -horizMove.x, horizMove.x * 2) * m_EarthQuakeWeaponShakeFactor);
        }

        // vertical move is always applied to the camera spring. this
        // feels cool though it impairs aiming.
        // then again ... it's a friggin' earthquake! :)
        m_PositionSpring.AddForce(new Vector3(0, vertMove, 0));
    }