Пример #1
0
        public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            SetLayerWeights(layerIndex);
            if (stateInfo.shortNameHash == h_Empty)
            {
                if (UseMirrorThrow)
                {
                    animator.SetBool("MirrorThrow", true);
                }
                else
                {
                    animator.SetBool("MirrorThrow", false);
                }
                if (!animator.IsInTransition(layerIndex) && ThrowTrigger())
                {
                    return;
                }
                if (!animator.IsInTransition(layerIndex) && SwitchThrowableTrigger(false))
                {
                    return;
                }
            }
            else if (stateInfo.shortNameHash == h_PullOut)
            {
            }
            else if (stateInfo.shortNameHash == h_ToReady)
            {
            }
            else if (stateInfo.shortNameHash == h_ReadyIdle)
            {
                if (!cExploderClone && animator.GetInteger(cap_Throw) != 2)
                {
                    // Unintentional Explosion
                    IsThrowing = false;
                    animator.SetInteger(cap_Throw, 0);
                    CalculateNextThrowable();
                    Events.InvokeThrowableExit(null);
                    return;
                }

                if (!animator.IsInTransition(layerIndex) && SwitchThrowableTrigger(true))
                {
                    return;
                }

                if (IndicatorTrigger() /* || 1 == 1*/) // uncomment to debug
                {
                    Vector3 targThrowDir = Quaternion.AngleAxis(-cExploderClone.additionalThrowAngleHorizontal, userInput.cameraRig.up) * (-transform.position + refTarget.position).normalized;

                    throwDir = targThrowDir;

                    SetThrowDistance();

                    if (cExploderClone.showEstimatedRoute)
                    {
                        cExploderClone.lineRendEnabled = true;
                    }
                    cExploderClone.FireStrength = Mathf.Lerp(
                        cExploderClone.throwForceMinMax.x, cExploderClone.throwForceMinMax.y,
                        animator.GetFloat(cap_ThrowDistance));
                    cExploderClone.FireDir = throwDir;
                }
                else /*if (1 == 0)*/ // uncomment to debug
                {
                    animator.SetInteger(cap_Throw, -1);
                    cExploderClone.lineRendEnabled = false;
                }

                SetThrowDistance();
            }
            else if (stateInfo.shortNameHash == h_Throw)
            {
            }
        }
Пример #2
0
        public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            horizontal = userInput.Horizontal;
            vertical   = userInput.Vertical;

            if (!animator.GetBool(cap_Grounded))
            {
                animator.SetFloat(cap_VelocityYPar, Mathf.Lerp(animator.GetFloat(cap_VelocityYPar), playerT.GetComponent <Rigidbody>().velocity.y, Time.deltaTime * player.jumpProps.velocityParamSmooth));
            }

            if (stateInfo.shortNameHash == _RunJumpStartState || stateInfo.shortNameHash == _idleJumpStartState || stateInfo.shortNameHash == footOnGround ||
                stateInfo.shortNameHash == _toIdleState || stateInfo.shortNameHash == handOnGround || stateInfo.shortNameHash == _rollState ||
                stateInfo.shortNameHash == _toRunState || stateInfo.shortNameHash == _handOnGroundWaitState || stateInfo.shortNameHash == _handOnGroundToIdleState)
            {
                return;
            }

            Vector3 moveDirection = Vector3.zero;
            float   targetAngle   = 0f;

            CalculateRefs(ref moveDirection, ref targetAngle, userInput.Horizontal, userInput.Vertical);

            float angleSmooth = Mathf.Lerp(0, targetAngle, moveDirection.magnitude * Time.deltaTime * player.jumpProps.airRotationSpeed);

            if (player.jumpProps.useTorqueRotation)
            {
                rb.AddTorque(playerT.up * angleSmooth, ForceMode.VelocityChange);
            }
            else
            {
                player.transform.rotation = Quaternion.Euler(0, angleSmooth, 0) * player.transform.rotation;
            }

            if (isOnAir(stateInfo))
            {
                Vector3 stickDirection = new Vector3(userInput.Horizontal, 0, userInput.Vertical);
                Vector3 camDirection   = moveReference.forward;
                camDirection.y = 0;
                Quaternion refShift1           = Quaternion.FromToRotation(Vector3.forward, camDirection);
                Vector3    targetMoveDirection = refShift1 * stickDirection;
                player.playerPhysic.MoveDir             = targetMoveDirection;
                player.playerPhysic.AddJumpControlForce = true;
            }
            else
            {
                player.playerPhysic.AddJumpControlForce = false;
            }

            if (rb.velocity.y < player.jumpProps.airDownForceStartVelocity)
            {
                player.playerPhysic.AddJumpDownForce = true;
            }
            else
            {
                player.playerPhysic.AddJumpDownForce = false;
            }

            float sqrM = Vector2.SqrMagnitude(new Vector2(horizontal, vertical)) > 1 ? Vector2.SqrMagnitude(new Vector2(horizontal, vertical).normalized) : Vector2.SqrMagnitude(new Vector2(horizontal, vertical));

            animator.SetFloat("Speed", sqrM, .2f, Time.deltaTime);

            if (animator.GetBool(cap_Grounded))
            {
                player.playerPhysic.AddJumpControlForce = false;
                player.playerPhysic.AddJumpDownForce    = false;
            }
        }
Пример #3
0
        public override void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            if (stateInfo.shortNameHash == h_ToCover)
            {
                Vector3 lerpPos = calced_GroundPoint + calced_CoverNormal * CCoverProps.distFromWall;

                transform.position = Vector3.Lerp(transform.position, lerpPos, Time.deltaTime * CCoverProps.toCoverPositionLerpSpeed);
                transform.forward  = Vector3.Lerp(transform.forward,
                                                  Quaternion.Euler(0,
                                                                   CCoverProps.yRotationFixer * Mathf.Sign(animator.GetFloat(cap_CoverSide)), 0) * calced_CoverNormal,
                                                  Time.deltaTime * CCoverProps.toCoverRotationLerpSpeed);
            }
            else if (stateInfo.shortNameHash == h_CoverLocom)
            {
                transform.forward = Vector3.Lerp(transform.forward,
                                                 Quaternion.Euler(0,
                                                                  CCoverProps.yRotationFixer * Mathf.Sign(animator.GetFloat(cap_CoverSide)), 0) * calced_CoverNormal,
                                                 Time.deltaTime * CCoverProps.toCoverRotationLerpSpeed);

                Vector3 lerpPos = calced_GroundPoint + calced_CoverNormal * CCoverProps.distFromWall;
                transform.position = Vector3.Lerp(transform.position, lerpPos, Time.deltaTime * CCoverProps.toCoverPositionLerpSpeed);
                animator.ApplyBuiltinRootMotion();
            }
            else if (stateInfo.tagHash == ht_SwitchSide)
            {
                Vector3 lerpPos = calced_GroundPoint + calced_CoverNormal * CCoverProps.distFromWall;

                transform.position = Vector3.Lerp(transform.position, lerpPos, Time.deltaTime * CCoverProps.toCoverPositionLerpSpeed);
                transform.forward  = Vector3.Lerp(transform.forward,
                                                  Quaternion.Euler(0,
                                                                   CCoverProps.yRotationFixer * Mathf.Sign(animator.GetFloat(cap_CoverSide)), 0) * calced_CoverNormal,
                                                  Time.deltaTime * CCoverProps.toCoverRotationLerpSpeed);
            }
            else
            {
                animator.ApplyBuiltinRootMotion();
            }
        }
Пример #4
0
        void ControlMovementPhysics()
        {
            float h = Input.GetAxis("Horizontal");                  // 入力デバイスの水平軸をhで定義
            float v = Input.GetAxis("Vertical");                    // 入力デバイスの垂直軸をvで定義

            anim.SetFloat("Speed", v);                              // Animator側で設定している"Speed"パラメタにvを渡す
            anim.SetFloat("Direction", h);                          // Animator側で設定している"Direction"パラメタにhを渡す
            anim.speed       = animSpeed;                           // Animatorのモーション再生速度に animSpeedを設定する
            currentBaseState = anim.GetCurrentAnimatorStateInfo(0); // 参照用のステート変数にBase Layer (0)の現在のステートを設定する
            rb.useGravity    = true;                                //ジャンプ中に重力を切るので、それ以外は重力の影響を受けるようにする



            // 以下、キャラクターの移動処理
            velocity = new Vector3(0, 0, v);       // 上下のキー入力からZ軸方向の移動量を取得
            // キャラクターのローカル空間での方向に変換
            velocity = transform.TransformDirection(velocity);
            //以下のvの閾値は、Mecanim側のトランジションと一緒に調整する
            if (v > 0.1)
            {
                velocity *= forwardSpeed;       // 移動速度を掛ける
            }
            else if (v < -0.1)
            {
                velocity *= backwardSpeed;  // 移動速度を掛ける
            }

            if (Input.GetButtonDown("Jump"))
            { // スペースキーを入力したら
                //アニメーションのステートがLocomotionの最中のみジャンプできる
                if (currentBaseState.nameHash == locoState)
                {
                    //ステート遷移中でなかったらジャンプできる
                    if (!anim.IsInTransition(0))
                    {
                        rb.AddForce(Vector3.up * jumpPower, ForceMode.Impulse);
                        anim.SetBool("Jump", true);        // Animatorにジャンプに切り替えるフラグを送る
                    }
                }
            }

            // 以下、Animatorの各ステート中での処理
            // Locomotion中
            // 現在のベースレイヤーがlocoStateの時
            if (currentBaseState.nameHash == locoState)
            {
                //カーブでコライダ調整をしている時は、念のためにリセットする
                if (useCurves)
                {
                    ResetCollider();
                }
            }
            // JUMP中の処理
            // 現在のベースレイヤーがjumpStateの時
            else if (currentBaseState.nameHash == jumpState)
            {
                // ステートがトランジション中でない場合
                if (!anim.IsInTransition(0))
                {
                    // 以下、カーブ調整をする場合の処理
                    if (useCurves)
                    {
                        // 以下JUMP00アニメーションについているカーブJumpHeightとGravityControl
                        // JumpHeight:JUMP00でのジャンプの高さ(0〜1)
                        // GravityControl:1⇒ジャンプ中(重力無効)、0⇒重力有効
                        float jumpHeight     = anim.GetFloat("JumpHeight");
                        float gravityControl = anim.GetFloat("GravityControl");
                        if (gravityControl > 0)
                        {
                            rb.useGravity = false;  //ジャンプ中の重力の影響を切る
                        }
                        // レイキャストをキャラクターのセンターから落とす
                        Ray        ray     = new Ray(transform.position + Vector3.up, -Vector3.up);
                        RaycastHit hitInfo = new RaycastHit();
                        // 高さが useCurvesHeight 以上ある時のみ、コライダーの高さと中心をJUMP00アニメーションについているカーブで調整する
                        if (Physics.Raycast(ray, out hitInfo))
                        {
                            if (hitInfo.distance > useCurvesHeight)
                            {
                                col.height = orgColHight - jumpHeight;         // 調整されたコライダーの高さ
                                float adjCenterY = orgVectColCenter.y + jumpHeight;
                                col.center = new Vector3(0, adjCenterY, 0);    // 調整されたコライダーのセンター
                            }
                            else
                            {
                                // 閾値よりも低い時には初期値に戻す(念のため)
                                ResetCollider();
                            }
                        }
                    }
                    // Jump bool値をリセットする(ループしないようにする)
                    anim.SetBool("Jump", false);
                }
            }
            else if (currentBaseState.nameHash == sweepState)
            {
                if (!anim.IsInTransition(0))
                {
                    anim.SetBool("Sweep", false);
                }
                velocity = new Vector3(0, 0, 0);
            }
            else if (currentBaseState.nameHash == thrustState)
            {
                if (!anim.IsInTransition(0))
                {
                    anim.SetBool("Thrust", false);
                }
                velocity = new Vector3(0, 0, 0);
            }
            else if (currentBaseState.nameHash == evadeState)
            {
                // While evading, ignore forward speed
                if (x > 0.1 || x < -0.1)
                {
                    velocity = transform.TransformDirection(new Vector3(x, 0, 0)) * evadeSpeed;
                }
                if (!anim.IsInTransition(0))
                {
                    anim.SetBool("Evade", false);
                    x = 0.0f;
                }
            }
            else if (currentBaseState.nameHash == blockState)
            {
                velocity /= 3;
            }
            // IDLE中の処理
            // 現在のベースレイヤーがidleStateの時
            else if (currentBaseState.nameHash == idleState)
            {
                //カーブでコライダ調整をしている時は、念のためにリセットする
                if (useCurves)
                {
                    ResetCollider();
                }
                // スペースキーを入力したらRest状態になる
                if (Input.GetButtonDown("Jump"))
                {
                    anim.SetBool("Rest", true);
                }
            }
            // REST中の処理
            // 現在のベースレイヤーがrestStateの時
            else if (currentBaseState.nameHash == restState)
            {
                //cameraObject.SendMessage("setCameraPositionFrontView");       // カメラを正面に切り替える
                // ステートが遷移中でない場合、Rest bool値をリセットする(ループしないようにする)
                if (!anim.IsInTransition(0))
                {
                    anim.SetBool("Rest", false);
                }
            }

            // 上下のキー入力でキャラクターを移動させる
            transform.localPosition += velocity * Time.fixedDeltaTime;

            // 左右のキー入力でキャラクタをY軸で旋回させる
            transform.Rotate(0, h * rotateSpeed, 0);
        }
Пример #5
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);
                    }
                }
            }
        }