Пример #1
0
    private void Explode()
    {
        GameObject dInst = (GameObject)Instantiate(detonationPrefab, transform.position, transform.rotation);

        AreaDamage aDmg = dInst.GetComponent <AreaDamage>();

        if (aDmg != null)
        {
            if (onlyVisual)
            {
                aDmg.enabled = false;
            }
            else
            {
                aDmg.overrideMaxDmg   = explosionDamage;
                aDmg.overrideMaxRange = explosionRadius;
            }
        }

        TimeScaleSound tss = dInst.GetComponent <TimeScaleSound>();

        if (tss != null)
        {
            tss.UpdatePitch(Random.Range(0.88f, 1f));
            tss.PlaySound();
        }
        else if (dInst.GetComponent <AudioSource>() != null)
        {
            dInst.GetComponent <AudioSource>().pitch *= Random.Range(0.88f, 1f);
        }

        RemoveInstance();
    }
Пример #2
0
    void Update()
    {
        float receivedRunSpeed = AntiHackSystem.RetrieveFloat("runSpeed");

        inputVector = (!RestrictionManager.restricted && !RestrictionManager.mpMatchRestrict) ? new Vector2(cInput.GetAxis("Horizontal Move"), cInput.GetAxis("Vertical Move")) : Vector2.zero;

        bool reloading = (wm.currentGC != null && wm.currentGC.reloading);

        if (!RestrictionManager.restricted && (grounded || controller.isGrounded) && !onLadder)
        {
            if (cInput.GetButton("Run") && inputVector.y >= 0.15f && pv.canSprint && !ac.isAiming && (Time.time - lastRunTime) >= 0.5f && !dm.animationIsPlaying)
            {
                runOnce = false;

                if (reloading)
                {
                    sprintReloadBoost = 1.25f;
                }
                else
                {
                    if (xyVelocity >= Mathf.Clamp(curSpeed, 0f, receivedRunSpeed) * 0.45f * weightFactor * slopeMod)
                    {
                        if (!crouching)
                        {
                            sprinting = true;
                            walking   = false;
                        }

                        if (CanStandUp())
                        {
                            crouching = false;
                        }
                    }
                    else if (xyVelocity < receivedRunSpeed * 0.2f)
                    {
                        sprinting = false;
                    }

                    sprintReloadBoost = 1f;
                }
            }
            else
            {
                sprintReloadBoost = 1f;
                sprinting         = false;
            }

            if (cInput.GetButtonDown("Walk") && !sprinting && !crouching)
            {
                walking = !walking;
            }

            if (cInput.GetButtonDown("Crouch") && !sprinting && (Time.time - lastCrouchTime) >= 0.25f)
            {
                if (!crouching)
                {
                    ia.DoImpactAnimation(2.5f);
                    crouching = true;

                    movement.crouchDetection.gameObject.SetActive(true);
                }
                else
                {
                    if (CanStandUp())
                    {
                        ia.DoImpactAnimation(1.9f);
                        crouching = false;
                        movement.crouchDetection.gameObject.SetActive(false);
                    }
                }

                walking        = false;
                lastCrouchTime = Time.time;
            }
        }

        if (!sprinting && !runOnce && !reloading)
        {
            lastRunTime = Time.time;
            runOnce     = true;
        }

        float animSpeed      = Time.deltaTime * 8.5f;
        float fovLegsClipMod = (GameSettings.settingsController.FOV - 60) * 0.0065f;

        if (crouching && xyVelocity >= 0.5f)
        {
            controller.height = Mathf.Lerp(controller.height, movement.crouchHeight + 0.1f, animSpeed);
            animations.playerMesh.transform.localPosition = Vector3.Lerp(animations.playerMesh.transform.localPosition, defaultLegPos - new Vector3(0f, 0.31f, fovLegsClipMod), animSpeed);
        }
        else if (crouching && xyVelocity < 0.5f)
        {
            controller.height = Mathf.Lerp(controller.height, movement.crouchHeight, animSpeed);
            animations.playerMesh.transform.localPosition = Vector3.Lerp(animations.playerMesh.transform.localPosition, defaultLegPos - new Vector3(0f, 0.57f, fovLegsClipMod), animSpeed);
        }
        else
        {
            controller.height = Mathf.Lerp(controller.height, defaultHeight, animSpeed);
            animations.playerMesh.transform.localPosition = Vector3.Lerp(animations.playerMesh.transform.localPosition, defaultLegPos - new Vector3(0f, 0f, fovLegsClipMod), animSpeed);
        }

        if (onLadder)
        {
            wasSprinting = false;
            sprinting    = false;

            if (!RestrictionManager.restricted && cInput.GetButtonDown("Jump") && pv.curStamina > 5 && Time.time - ladderLatchTime >= 0.4f)
            {
                climbDir = 0f; //Avoid unlatch force.
                UnlatchLadder();
                velocity      += (-tr.forward * 2f) + (Vector3.up * 1.25f);
                pv.curStamina -= 5;
                jumpTime       = Time.time + 0.1f;
                AudioSource.PlayClipAtPoint(footsteps.jumpOffLadder, footsteps.footstepPos.transform.position, 0.5f);
            }
        }

        float heightOffset = ((defaultHeight - controller.height) * -0.5f);

        head.localPosition = defaultHeadPos + (Vector3.up * (0.05f + (heightOffset * 2f)));
        Vector3 targetCenter = Vector3.up * (heightOffset + 0.9f);

        if (controller.center != targetCenter)
        {
            controller.center = targetCenter;
        }

        botDetector.center = controller.center;
        botDetector.radius = controller.radius;
        botDetector.height = controller.height;

        if (grounded && sliding.slipInfluenceDist > 0.01f)
        {
            float movementInput = Mathf.Clamp01(moveDirection.sqrMagnitude);
            if (xyVelocity > 0.1f && movementInput > 0.001f)
            {
                influenceOffset = tr.TransformDirection(moveDirection.normalized);
            }

            Vector3 origin = tr.position + (influenceOffset * sliding.slipInfluenceDist);
            if (xyVelocity > 0.05f || influenceOffset != oldInfluenceOffset)
            {
                if (!Physics.Linecast(origin, origin + (Vector3.down * 1.2f), sliding.slipOnLayers.value))
                {
                    isSlipping = true;
                }
                else
                {
                    isSlipping = false;
                }

                oldInfluenceOffset = influenceOffset;
            }
        }

        slipMovement = (isSlipping) ? influenceOffset : Vector3.zero;

        weightFactor   = 1f - (wc.weightPercentage * 0.3f);
        impactMod      = Mathf.MoveTowards(impactMod, 1f, Time.deltaTime * 0.7f);
        diagonalFactor = (inputVector != Vector2.zero && !sprinting) ? (1f / Mathf.Max(1f, inputVector.magnitude)) : 1f;
        moveDirection  = new Vector3(inputVector.x * ((sprinting) ? 0.3f : 1f), 0f, inputVector.y) * diagonalFactor * weightFactor * impactMod;

        Vector3 velo = velocity;

        velo = ApplyInputVelocity(velo);
        velo = ApplyGravityAndJump(velo);
        Vector3 currentMovementOffset = velo * Time.deltaTime;

        if (grounded)
        {
            currentMovementOffset += Vector3.down * movement.pushDownFactor * Time.deltaTime;
        }

        if (activePlatform != null && (grounded || movingPlatform.movementTransfer == MovementTransferOnJump.PermaLocked))
        {
            try
            {
                Vector3 pointDiff = (activePlatform.TransformPoint(activeLocalPoint) - activeGlobalPoint);
                smoothPlatform   = Vector3.Lerp(smoothPlatform, pointDiff, Time.deltaTime * movingPlatform.platformSmoothing);
                smoothPlatform.y = pointDiff.y;

                if (smoothPlatform != Vector3.zero)
                {
                    controller.Move(smoothPlatform);
                }

                Quaternion rotationDiff = (activePlatform.rotation * activeLocalRotation) * Quaternion.Inverse(activeGlobalRotation);

                if (rotationDiff.eulerAngles.y != 0f)
                {
                    pl.xRot += rotationDiff.eulerAngles.y;
                }
            }
            catch
            {
            }
        }

        groundNormal = Vector3.zero;

        Vector3 lastPosition = tr.position;

        collisionFlags   = controller.Move(currentMovementOffset);
        lastHitPoint     = hitPoint;
        lastGroundNormal = groundNormal;

        Vector3 oldHVelocity = new Vector3(velo.x, 0f, velo.z);

        velocity = (tr.position - lastPosition) / Mathf.Max(0.0001f, Time.deltaTime);
        Vector3 newHVelocity = new Vector3(velocity.x, 0f, velocity.z);

        if (oldHVelocity == Vector3.zero)
        {
            velocity = Vector3.up * velocity.y;
        }
        else
        {
            float projectedNewVelocity = Vector3.Dot(newHVelocity, oldHVelocity) / oldHVelocity.sqrMagnitude;
            velocity = oldHVelocity * Mathf.Clamp01(projectedNewVelocity) + (Vector3.up * velocity.y);
        }

        if (velocity.y < velo.y - 0.001f)
        {
            if (velocity.y < 0f)
            {
                velocity.y = velo.y;
            }
        }

        if (pauseVelocity != Vector3.zero && Time.timeScale > 0f)
        {
            velocity     += pauseVelocity; //Apply saved velocity.
            pauseVelocity = Vector3.zero;
        }

        if (!controller.isGrounded)
        {
            isSlipping = false;
        }

        if ((grounded && !controller.isGrounded && groundNormal.y <= 0.01f) || didJump)
        {
            grounded = (controller.collisionFlags & CollisionFlags.Below) != 0;

            if (!grounded)
            {
                if (!didJump)
                {
                    velocity -= Vector3.up * movement.gravity * 0.1f;
                }

                if (!didJump && movingPlatform.movementTransfer == MovementTransferOnJump.InitTransfer || movingPlatform.movementTransfer == MovementTransferOnJump.PermaTransfer)
                {
                    frameVelocity = platformVelocity;
                    velocity     += platformVelocity;
                }

                if (sprinting)
                {
                    wasSprinting       = true;
                    sprintJumpRestrict = 0.15f;
                    sprinting          = false;
                }

                ia.FallAnimation();
                playerMeshAnim.CrossFade(animations.jumpAnim, 0.2f);
                didJump = false;
            }
        }
        else if (!grounded && controller.isGrounded && groundNormal.y > 0.01f)
        {
            grounded = true;
            StartCoroutine(SubtractNewPlatformVelocity());

            if (onLadder)
            {
                UnlatchLadder();
            }

            float impactVelo = Mathf.Abs(velo.y);
            if (impactVelo >= 0.5f)
            {
                footsteps.footstepPos.volume = 0.1f + Mathf.Clamp(0.023f * impactVelo, 0f, 0.64f);
                tss.UpdatePitch(Random.Range(0.88f, 0.95f));
                SelectFootstep();
                tss.GetComponent <AudioSource>().PlayOneShot(footSound);
                stepTimer = 0f;

                if (standingRigidbody != null)
                {
                    Vector3 rigidImpact = controller.velocity;
                    rigidImpact.y *= (0.05f * physics.mass);
                    rigidImpact.y  = Mathf.Max(-5f, rigidImpact.y);
                    standingRigidbody.AddForceAtPosition(rigidImpact, transform.position, ForceMode.Impulse);
                }

                impactMod = 1f - Mathf.Clamp((impactVelo - 0.5f) * 0.08f, 0f, 0.5f);
                pv.FallDamage(impactVelo);
                ia.DoImpactAnimation(impactVelo - 0.32f);
            }

            wasSprinting = false;
        }

        if (activePlatform != null && (grounded || movingPlatform.movementTransfer == MovementTransferOnJump.PermaLocked))
        {
            activeGlobalPoint = tr.position + Vector3.up * (controller.center.y - (controller.height * 0.5f) + controller.radius);
            activeLocalPoint  = activePlatform.InverseTransformPoint(activeGlobalPoint);

            activeGlobalRotation = tr.rotation;
            activeLocalRotation  = Quaternion.Inverse(activePlatform.rotation) * activeGlobalRotation;
        }

        Vector3 controllerVelo = controller.velocity;

        controllerVeloMagn = controllerVelo.magnitude;
        controllerVelo.y   = 0f;
        xyVelocity         = controllerVelo.magnitude;

        isMoving = (controllerVeloMagn > 0.25f);

        if (((grounded && controller.isGrounded) || onLadder) && footsteps.enabled && !isSliding)
        {
            if (sprinting)
            {
                stepRate = Mathf.Lerp(stepRate, footsteps.sprintStepRate, Time.deltaTime * 8f);
            }
            else if (sprintReloadBoost > 1f)
            {
                stepRate = Mathf.Lerp(stepRate, footsteps.runStepRate * 1.1f, Time.deltaTime * 8f);
            }
            else if (onLadder)
            {
                stepRate = Mathf.Lerp(stepRate, footsteps.ladderStepRate, Time.deltaTime * 8f);
            }
            else
            {
                stepRate = Mathf.Lerp(stepRate, footsteps.runStepRate, Time.deltaTime * 8f);
            }

            if (Mathf.Abs(inputVector.x) + Mathf.Abs(inputVector.y) >= 0.05f)
            {
                stepTimer += controllerVeloMagn * Time.deltaTime;
            }

            if (stepTimer >= stepRate)
            {
                if (sprinting)
                {
                    footsteps.footstepPos.volume = 0.175f;
                }
                else if (crouching || walking)
                {
                    footsteps.footstepPos.volume = 0.07f;
                }
                else
                {
                    footsteps.footstepPos.volume = 0.12f;
                }

                tss.UpdatePitch(Random.Range(0.9f, 1.0f));
                SelectFootstep();
                footsteps.footstepPos.PlayOneShot(footSound);
                stepTimer -= stepRate;
            }
        }

        if (animations.enabled && xyVelocity > 0.5f && !isSliding)
        {
            if (sprinting)
            {
                playerMeshAnim[animations.runAnim].speed = xyVelocity * 0.18f;
                playerMeshAnim.CrossFade(animations.runAnim, 0.25f);
            }
            else
            {
                Vector3 moveDir = moveDirection.normalized;

                if (crouching)
                {
                    float animVeloSpeed = xyVelocity * 0.5f;

                    if (moveDir.z > 0.05f)
                    {
                        playerMeshAnim[animations.crouchForwardAnim].speed = animVeloSpeed;
                        playerMeshAnim.CrossFade(animations.crouchForwardAnim, 0.25f);
                    }
                    else if (moveDir.z < -0.05f)
                    {
                        playerMeshAnim[animations.crouchForwardAnim].speed = -animVeloSpeed;
                        playerMeshAnim.CrossFade(animations.crouchForwardAnim, 0.25f);
                    }
                    else if (moveDir.x < -0.05f)
                    {
                        playerMeshAnim[animations.crouchLeftAnim].speed = animVeloSpeed;
                        playerMeshAnim.CrossFade(animations.crouchLeftAnim, 0.25f);
                    }
                    else if (moveDir.x > 0.05f)
                    {
                        playerMeshAnim[animations.crouchRightAnim].speed = animVeloSpeed;
                        playerMeshAnim.CrossFade(animations.crouchRightAnim, 0.25f);
                    }
                }
                else
                {
                    float animVeloSpeed = xyVelocity * 0.25f;

                    if (moveDir.z > 0.05f)
                    {
                        playerMeshAnim[animations.runAnim].speed = animVeloSpeed;
                        playerMeshAnim.CrossFade(animations.runAnim, 0.25f);
                    }
                    else if (moveDir.z < -0.05f)
                    {
                        if (animations.runBackAnim != "")
                        {
                            playerMeshAnim[animations.runBackAnim].speed = animVeloSpeed;
                            playerMeshAnim.CrossFade(animations.runBackAnim, 0.25f);
                        }
                        else
                        {
                            playerMeshAnim[animations.runAnim].speed = -animVeloSpeed;
                            playerMeshAnim.CrossFade(animations.runAnim, 0.25f);
                        }
                    }
                    else if (moveDir.x < -0.05f)
                    {
                        playerMeshAnim[animations.runLeftAnim].speed = animVeloSpeed;
                        playerMeshAnim.CrossFade(animations.runLeftAnim, 0.25f);
                    }
                    else if (moveDir.x > 0.05f)
                    {
                        playerMeshAnim[animations.runRightAnim].speed = animVeloSpeed;
                        playerMeshAnim.CrossFade(animations.runRightAnim, 0.25f);
                    }
                }
            }
        }

        if (animations.enabled && xyVelocity <= 0.5f)
        {
            if (crouching && !isSliding)
            {
                playerMeshAnim.CrossFade(animations.crouchAnim, 0.25f);
            }
            else
            {
                playerMeshAnim.CrossFade(animations.idleAnim, 0.25f);
            }
        }

        if (activePlatform != null)
        {
            if (!newPlatform)
            {
                platformVelocity = ((Time.deltaTime > 0f) ? (activePlatform.localToWorldMatrix.MultiplyPoint3x4(activeLocalPoint) - lastMatrix.MultiplyPoint3x4(activeLocalPoint)) / Time.deltaTime : Vector3.zero);
            }

            lastMatrix  = activePlatform.localToWorldMatrix;
            newPlatform = false;
        }
        else
        {
            platformVelocity = Vector3.zero;
        }

        fDmgSpeedMult = Mathf.Clamp(fDmgSpeedMult, 0.5f, 1f);
        fDmgSpeedMult = Mathf.MoveTowards(fDmgSpeedMult, 1f, Time.deltaTime * 0.007f);

        if (pauseVelocity == Vector3.zero && Time.timeScale <= 0f)
        {
            pauseVelocity = velocity; //Maintain velocity until the next time you un-pause.
        }
    }