AddForce() public method

public AddForce ( Vector3 force ) : void
force Vector3
return void
    ///////////////////////////////////////////////////////////
    // applies various forces to the camera and weapon springs
    // in response to falling impact
    ///////////////////////////////////////////////////////////
    public void ApplyFallImpact(float impact)
    {
        float posImpact = impact * PositionKneeling;
        float rotImpact = impact * RotationKneeling;

        // smooth step the impacts to make the springs react more subtly
        // from short falls, and more aggressively from longer falls

        posImpact = Mathf.SmoothStep(0, 1, posImpact);
        posImpact = Mathf.Clamp01(posImpact);

        rotImpact = Mathf.SmoothStep(0, 1, rotImpact);
        rotImpact = Mathf.SmoothStep(0, 1, rotImpact);
        rotImpact = Mathf.Clamp01(rotImpact);

        // apply impact to camera position spring
        if (m_PositionSpring != null)
        {
            m_PositionSpring.AddForce(new Vector3(0, -posImpact, 0));
        }

        // apply impact to camera rotation spring
        if (m_RotationSpring != null)
        {
            float roll = Random.value > 0.5f ? (rotImpact * 2) : -(rotImpact * 2);
            m_RotationSpring.AddForce(new Vector3(0, 0, roll));
        }

        // apply falling impact on the current weapon, if present
        if (m_CurrentWeapon != null)
        {
            m_CurrentWeapon.ApplyFallImpact(posImpact);
        }
    }
Beispiel #2
0
    /// <summary>
    /// applies positional and angular force to the weapon. the
    /// typical use for this method is applying recoil force.
    /// </summary>
    public virtual void AddForce2(Vector3 positional, Vector3 angular)
    {
        if (m_PositionSpring2 != null)
        {
            m_PositionSpring2.AddForce(positional);
        }

        if (m_RotationSpring2 != null)
        {
            m_RotationSpring2.AddForce(angular);
        }
    }
Beispiel #3
0
 /// <summary>
 /// applies positional and angular force to the weapon
 /// </summary>
 public virtual void AddForce(Vector3 positional, Vector3 angular)
 {
     m_PositionSpring.AddForce(positional);
     m_RotationSpring.AddForce(angular);
 }
Beispiel #4
0
 /// <summary>
 /// pushes the weapon position spring along the 'force' vector
 /// for one frame. For external use.
 /// </summary>
 public virtual void AddForce(Vector3 force)
 {
     m_PositionSpring.AddForce(force);
 }
 ///////////////////////////////////////////////////////////
 // pushes the 2nd camera position spring along the 'force'
 // vector for one frame. for external use.
 ///////////////////////////////////////////////////////////
 public void AddForce2(Vector3 force)
 {
     m_PositionSpring2.AddForce(force);
 }
 /// <summary>
 /// twists the camera around its z vector for one frame
 /// </summary>
 public virtual void AddRollForce(float force)
 {
     m_RotationSpring.AddForce(Vector3.forward * force);
 }
Beispiel #7
0
 public void Recoil()
 {
     recoilUpwardSpring.AddForce(Vector3.left * recoilUpwardMagnitude);
     recoilBackwardSpring.AddForce(Vector3.back * recoilBackwardMagnitude);
 }
Beispiel #8
0
        void FixedUpdate()
        {
            // get input
            if (scrFpsController.getInput == null)
            {
                return;
            }

            FpsControllerInput input = scrFpsController.getInput();

            // lerp toward shouldered or unshouldered position
            float intensityMultiplier = 1f;

            if (shouldering)
            {
                currentRotation = Quaternion.Lerp(currentRotation, Quaternion.Euler(0f, 0f, 0f), shoulderLerp);
                currentPosition = Vector3.Lerp(currentPosition, shoulderingPosition, shoulderLerp);

                if (scrFpsController.grounded) // only have steady weapon if shouldering and grounded
                {
                    intensityMultiplier = shoulderMovementIntensityMult;
                }
            }
            else
            {
                currentRotation = Quaternion.Lerp(currentRotation, originalRotation, unshoulderLerp);
                currentPosition = Vector3.Lerp(currentPosition, originalPosition, unshoulderLerp);
            }

            // movement bob or vertical move inertia
            float movementBob = 0f;

            if (scrFpsController.grounded)
            {
                // vertical movement Bob
                movementBob      = movementBobIntensity * intensityMultiplier * scrFpsController.GetMoveSpeedPercent() * Mathf.Sin(movementBobTime);
                movementBobTime += Time.fixedDeltaTime * Mathf.Lerp(movementBobMinFrequency, movementBobMaxFrequency, scrFpsController.GetMoveSpeedPercent());
            }
            else
            {
                movementBobTime = 0f;

                // jump inertia
                moveInertiaSpring.AddForce(Vector3.down * -scrFpsController.body.velocity.y * moveInertiaMagnitude.y * intensityMultiplier * Time.fixedDeltaTime);
            }

            // look inertia
            lookInertiaSpring.AddSoftForce(new Vector3(
                                               input.lookY * -lookInertiaMagnitude.y * intensityMultiplier, // Look Vertical
                                               input.lookX * -lookInertiaMagnitude.x * intensityMultiplier, // Look Horizontal
                                               input.moveX * -moveBankMagnitude * intensityMultiplier),     // Movement Bank
                                           lookInertiaDistributeFrames);

            Vector3 rotatedVelocity = transform.InverseTransformDirection(scrFpsController.body.velocity);

            // move inertia
            moveInertiaSpring.AddForce(
                new Vector3(
                    -rotatedVelocity.x * moveInertiaMagnitude.x * Math.BoolToFloat(!(shouldering && scrFpsController.grounded)),
                    movementBob,
                    -rotatedVelocity.z * moveInertiaMagnitude.z * intensityMultiplier)
                * Time.fixedDeltaTime);

            // apply spring transformations
            transform.localRotation = currentRotation * Quaternion.Euler(lookInertiaSpring.UpdateState()) * Quaternion.Euler(recoilUpwardSpring.UpdateState());
            transform.localPosition = currentPosition + moveInertiaSpring.UpdateState() + recoilBackwardSpring.UpdateState();
        }