Beispiel #1
0
        public override void OnEnabled(Animator anim)
        {
            if (userInput.transform.FindChild("CoverChecker"))
            {
                coverChecker = player.transform.FindChild("CoverChecker").GetComponent <CoverTargetLogic>();
            }
            animator  = userInput.GetComponent <Animator>();
            transform = userInput.transform;
            if (userInput.cameraRig)
            {
                moveReference = userInput.cameraRig.FindChild("Move Reference");
                playerCamera  = userInput.cameraRig.GetComponent <PlayerCamera>();
            }

            foreach (Transform tr in userInput.cameraRig.GetComponentsInChildren <Transform>())
            {
                if (tr.CompareTag("Target"))
                {
                    RefTarget = tr;
                }
            }

            Events = new CoveringEvents();

            if (!coverChecker || !animator || !transform || !moveReference || !RefTarget || !playerCamera || player.defaultCoverStyleIndex >= player.coverStyles.Count)
            {
                userInput.DisablePlayer("Reference not found on :" + ToString());
            }

            TriggS = new LayersWithDefValue <SystemTrigger>(new CoverSystemTriggers());

            LayerWeightTarget = 0;
        }
Beispiel #2
0
        private void SetCrouchStand()
        {
            float crouchStand = CoverTargetLogic.RequestCrouch(CCoverProps.characterHeight, CCoverProps.crouchRayCheckCount, CCoverProps.crouchCheckStartHeight,
                                                               CCoverProps.crouchCheckRayMaxDist,
                                                               calced_GroundPoint, calced_CoverNormal
                                                               );

            animator.SetFloat(cap_CrouchStand, crouchStand, CCoverProps.animParamDamp, Time.deltaTime);
        }
Beispiel #3
0
        public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            UpdateLayerWeight(layerIndex);
            if (stateInfo.shortNameHash == h_Empty)
            {
                if (!animator.IsInTransition(0))
                {
                    animator.SetFloat(cap_CrouchStand, 0, CCoverProps.animParamDamp, Time.deltaTime);
                }

                if (!animator.IsInTransition(0) && CoverAroundTrigger())
                {
                    return;
                }
            }
            else if (stateInfo.shortNameHash == h_ToCover)
            {
                float crouchStand = CoverTargetLogic.RequestCrouch(CCoverProps.characterHeight, CCoverProps.crouchRayCheckCount, CCoverProps.crouchCheckStartHeight,
                                                                   CCoverProps.crouchCheckRayMaxDist,
                                                                   calced_GroundPoint, calced_CoverNormal
                                                                   );
                animator.SetFloat(cap_CrouchStand, crouchStand, CCoverProps.animParamDamp, Time.deltaTime);
            }
            else if (stateInfo.shortNameHash == h_CoverLocom)
            {
                // Current Pos Check (with a fixed small distance to the opposite side)
                Vector3 coverNormalFromCPos    = Vector3.zero;
                Vector3 coverGroundHitFromCPos = Vector3.zero;
                bool    hasCoverCPos           = coverChecker.RequestCover(
                    new Ray(transform.position + Vector3.up * coverChecker.aroundPlRayStartUpHeight, -calced_CoverNormal),
                    ref coverNormalFromCPos, ref coverGroundHitFromCPos,
                    CCoverProps.rayLength, coverChecker.maxAllowedAngleVert, coverChecker.maxAllowedGroundNormalAngle
                    );
                if (hasCoverCPos)
                {
                    calced_CoverNormal = coverNormalFromCPos;
                    calced_GroundPoint = coverGroundHitFromCPos;
                }

                // Cover exit check & stick angle
                float stickAngleWorld = GetStickAngle();
                if (!animator.IsInTransition(layerIndex) && (CoverCameraTrigger() || ExitCoverTrigger(stickAngleWorld, hasCoverCPos)))
                {
                    return;
                }

                // Next Pos Check
                Ray rayNext = new Ray(coverGroundHitFromCPos + Vector3.up * coverChecker.aroundPlRayStartUpHeight +
                                      Quaternion.Euler(0, 90 * Mathf.Sign(animator.GetFloat(cap_CoverSide)), 0) * calced_CoverNormal * CCoverProps.sideRayDist, -calced_CoverNormal);
                Vector3 coverNormalFromNextPos = Vector3.zero;
                Vector3 coverGroundHitNextPos  = Vector3.zero;
                bool    hasCoverNextPos        = coverChecker.RequestCover(
                    rayNext, ref coverNormalFromNextPos, ref coverGroundHitNextPos,
                    CCoverProps.rayLength, coverChecker.maxAllowedAngleVert, coverChecker.maxAllowedGroundNormalAngle
                    );

                // Camera look angle / Peek triggers
                float angle = GetAngle();

                if (!animator.IsInTransition(layerIndex))
                {
                    if (animator.GetFloat(cap_CoverSide) < 0)
                    {
                        player.SmbThrow.UseMirrorThrow = true;
                    }
                    else
                    {
                        player.SmbThrow.UseMirrorThrow = false;
                    }
                    if (!hasCoverNextPos && userInput.Vertical < .1f && EdgePeekTrigger(angle))
                    {
                        return;
                    }
                    else if (UpPeekTrigger(angle))
                    {
                        return;
                    }
                }

                SetCrouchStand();

                if (MoveTrigger() && (!animator.IsInTransition(layerIndex) || animator.GetAnimatorTransitionInfo(layerIndex).nameHash == hTrans_leftSwitchToLocom ||
                                      animator.GetAnimatorTransitionInfo(layerIndex).nameHash == hTrans_rightSwitchToLocom) &&
                    Mathf.Abs(stickAngleWorld) > CCoverProps.startMoveAtStickAngle)
                {
                    stickAngleWorld = Mathf.Sign(stickAngleWorld);
                    // Switch side
                    if (stickAngleWorld != Mathf.Sign(animator.GetFloat(cap_CoverSide)))
                    {
                        SetSideSwitchTrigger();
                        return;
                    }

                    if (hasCoverNextPos)
                    {
                        animator.SetFloat(cap_Speed, Mathf.Abs(stickAngleWorld), CCoverProps.animSpeedDamp, Time.deltaTime);
                    }
                    else
                    {
                        animator.SetFloat(cap_Speed, 0, CCoverProps.animSpeedDamp, Time.deltaTime);
                    }
                }
                else
                {
                    animator.SetFloat(cap_Speed, 0, CCoverProps.animSpeedDamp, Time.deltaTime);
                }
            }
            else if (stateInfo.tagHash == ht_SwitchSide)
            {
                animator.SetFloat(cap_Speed, 0, CCoverProps.animSpeedDamp, Time.deltaTime);
            }
            else if (stateInfo.shortNameHash == h_ToPeek)
            {
                animator.SetFloat(cap_Speed, 0, CCoverProps.animSpeedDamp, Time.deltaTime);
            }
            else if (stateInfo.tagHash == hTag_Peek)
            {
                float angle = GetAngle();
                if (UnEdgePeekTrigger(angle))
                {
                    return;
                }

                float animAngle = 0;
                IsAngleInBounds(angle, CCoverProps.edgePeekAngleTolerance,
                                CCoverProps.oppositeDirMaxAngle, animator.GetFloat(cap_CoverSide) < 0, ref animAngle);
                if (!animator.IsInTransition(layerIndex))
                {
                    animator.SetFloat(cap_Angle, animAngle);
                }
            }
            else if (stateInfo.tagHash == hTag_UpPeek)
            {
                float angle = GetAngle();
                UnUpPeekTrigger(angle);

                if (!animator.IsInTransition(layerIndex))
                {
                    animator.SetFloat(cap_Angle, angle);
                }
                if (!animator.IsInTransition(layerIndex))
                {
                    animator.SetFloat(cap_CoverSide, Mathf.Sign(angle));
                }
            }
            else if (stateInfo.shortNameHash == h_MovingToCamCover)
            {
                // Exit cover completely
                if (!animator.IsInTransition(layerIndex) && userInput.AnyKeyDown())
                {
                    player.SmbLoco.ReleaseOverrideLocomoteType(c_OverrideKey_2);
                    animator.SetInteger(cap_Cover, -1);
                    LayerWeightTarget = 0;
                    return;
                }
                if (!animator.IsInTransition(layerIndex) && animator.GetInteger(cap_Cover) > 0 && player.SmbLoco.RemainingAgentDistance < CCoverProps.toCameraCoverStopDistance)
                {
                    if (coverChecker.HaveCoverAround && CoverAroundTrigger(true))
                    {
                        player.SmbLoco.ReleaseOverrideLocomoteType(c_OverrideKey_2);
                    }
                }
            }
        }