Exemplo n.º 1
0
    private void HandleLedgeStepMotion(PlayerController player)
    {
        AnimatorStateInfo      animState = player.Anim.GetCurrentAnimatorStateInfo(0);
        AnimatorTransitionInfo transInfo = player.Anim.GetAnimatorTransitionInfo(0);

        if (!waitingBool && isRootMotion && animState.IsName("Idle"))
        {
            player.EnableCharControl();
            isRootMotion = false;
        }
        else if (waitingBool && (animState.IsName("StepUp_Hlf") || animState.IsName("StepUp_Qtr") || animState.IsName("StepUp_Full")))
        {
            waitingBool          = false;
            player.UseRootMotion = true;

            Vector3               targetPosition = ledgeInfo.Point + ledgeInfo.Direction * 0.24f;
            Quaternion            targetRotation = Quaternion.LookRotation(ledgeInfo.Direction);
            MatchTargetWeightMask weightMask     = new MatchTargetWeightMask(Vector3.one, 1f);

            player.Anim.MatchTarget(targetPosition, targetRotation, AvatarTarget.Root, weightMask, 0.1f, 0.9f);
        }
        else if (transInfo.IsName("AnyState -> StepUp_Hlf") || transInfo.IsName("AnyState -> StepUp_Qtr") || transInfo.IsName("AnyState -> StepUp_Full"))
        {
            player.UseRootMotion = false;
        }
    }
Exemplo n.º 2
0
    void checkStates()
    {
        AnimatorStateInfo      asi = this.animator.GetCurrentAnimatorStateInfo(0);
        AnimatorTransitionInfo ati = this.animator.GetAnimatorTransitionInfo(0);

        this.climbing = asi.IsName("Climb") || ati.IsName("Run -> Climb") || ati.IsName("Climb -> Run");
    }
Exemplo n.º 3
0
    public override void Update(PlayerController player)
    {
        AnimatorStateInfo      animState = player.Anim.GetCurrentAnimatorStateInfo(0);
        AnimatorTransitionInfo transInfo = player.Anim.GetAnimatorTransitionInfo(0);

        if (hasJumped)
        {
            if (player.Grounded && player.Velocity.y <= 0f)
            {
                player.ForceWaistRotation = true;
                player.StateMachine.GoToState <Combat>();
                return;
            }
            else if (player.VerticalSpeed <= -player.DamageVelocity)
            {
                player.ForceWaistRotation = false;
                player.StateMachine.GoToState <InAir>();
                player.UpperStateMachine.GoToState <Empty>(); // Stops player glitching with guns out
                return;
            }
        }
        else
        {
            if (transInfo.IsName("CombatCompress -> JumpR"))
            {
                player.ForceWaistRotation = false;
                player.ImpulseVelocity(player.transform.right * player.RunJumpVel + Vector3.up * player.JumpYVel);
                hasJumped = true;
            }
            else if (transInfo.IsName("CombatCompress -> JumpL"))
            {
                player.ForceWaistRotation = false;
                player.ImpulseVelocity(player.transform.right * -player.RunJumpVel + Vector3.up * player.JumpYVel);
                hasJumped = true;
            }
            else if (transInfo.IsName("CombatCompress -> JumpB"))
            {
                player.ForceWaistRotation = false;
                player.ImpulseVelocity(player.transform.forward * -player.RunJumpVel + Vector3.up * player.JumpYVel);
                hasJumped = true;
            }
            else if (transInfo.IsName("CombatCompress -> JumpF"))
            {
                player.ImpulseVelocity(player.transform.forward * player.RunJumpVel + Vector3.up * player.JumpYVel);
                hasJumped = true;
            }
            else if (transInfo.IsName("CombatCompress -> JumpU"))
            {
                player.ImpulseVelocity(Vector3.up * player.JumpYVel);
                hasJumped = true;
            }
        }
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        EndTime = Time.time;

        if (EndTime - StartTime > 5.0f)
        {
            friendly++;
            StartTime = Time.time;
        }

        if (rand == (int)CatState.idle)
        {
        }
        else if (rand == (int)CatState.walk)
        {
        }
        else if (rand == (int)CatState.run)
        {
        }
        else if (rand == (int)CatState.play)
        {
        }
        else
        {
            anim.SetBool("Sleep", true);
        }

        AnimatorStateInfo      info  = anim.GetCurrentAnimatorStateInfo(0); //현재 애니메이션 상태
        AnimatorTransitionInfo info2 = anim.GetAnimatorTransitionInfo(0);   //현재 트랜지션 상태

        if (info2.IsName("F_idle -> F_sleep"))
        {
            Debug.Log("전환");
        }
    }
Exemplo n.º 5
0
 void checkStates()
 {
     if (this.boarding)
     {
         AnimatorStateInfo      asi = this.offsetAnimator.GetCurrentAnimatorStateInfo(0);
         AnimatorTransitionInfo ati = this.offsetAnimator.GetAnimatorTransitionInfo(0);
         this.inAir = asi.IsName("Hop") || ati.IsName("Hover -> Hop") || ati.IsName("Slide -> Hop");
     }
     else
     {
         AnimatorStateInfo      asi = this.animator.GetCurrentAnimatorStateInfo(0);
         AnimatorTransitionInfo ati = this.animator.GetAnimatorTransitionInfo(0);
         this.rolling  = asi.IsName("Slide") /*|| asi.IsName("Roll") || ati.IsName("Run -> Roll")*/ || ati.IsName("Run -> Slide") /*|| ati.IsName("Roll -> Run")*/ || ati.IsName("Slide -> Run") /*|| ati.IsName("Idle -> Roll")*/ || ati.IsName("Idle -> Slide");
         this.inAir    = asi.IsName("Jump") || ati.IsName("Run -> Jump");
         this.climbing = asi.IsName("Climb") || ati.IsName("Run -> Climb") || ati.IsName("Climb -> Run");
         //this.inAirColl = asi.IsName("Jump");
     }
 }
Exemplo n.º 6
0
    static int IsName(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        AnimatorTransitionInfo obj = LuaScriptMgr.GetNetObject <AnimatorTransitionInfo>(L, 1);
        string arg0 = LuaScriptMgr.GetLuaString(L, 2);
        bool   o    = obj.IsName(arg0);

        LuaScriptMgr.Push(L, o);
        return(1);
    }
Exemplo n.º 7
0
    /*This checks to ensure that both the current state and next state must be any of the given states
     */
    protected bool checkStateMustBe(string[] names)
    {
        AnimatorStateInfo info = anim.GetCurrentAnimatorStateInfo(0);
        //AnimatorStateInfo nextinfo=anim.GetNextAnimatorStateInfo(0);
        AnimatorTransitionInfo nextinfo = anim.GetAnimatorTransitionInfo(0);

        bool b = false, nextb = false;

        foreach (string name in names)
        {
            b     |= info.IsName(name);
            nextb |= nextinfo.IsName(name);
        }
        return(b || nextb);
    }
Exemplo n.º 8
0
    private bool TryMoveTurn()
    {
        AnimatorStateInfo      asInfo = m_Animator.GetCurrentAnimatorStateInfo(0);
        AnimatorTransitionInfo atInfo = m_Animator.GetAnimatorTransitionInfo(0);

        if (atInfo.IsName("idle -> run") || asInfo.IsName("run"))
        {
            if (MoveTurn(m_MoveDir))
            {
                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 9
0
    void Update()
    {
        AnimatorStateInfo      asi = Player.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0);
        AnimatorTransitionInfo ati = Player.GetComponent <Animator>().GetAnimatorTransitionInfo(0);

        this.inAir = asi.IsName("Jump") || ati.IsName("Run -> Jump");

        if (inCollsion)
        {
            if (inAir)
            {
                Debug.Log("Death");
                //death
            }
        }
    }
        void IsName()
        {
            if (_animator != null)
            {
                AnimatorTransitionInfo _info = _animator.GetAnimatorTransitionInfo(layerIndex.Value);

                if (_info.IsName(name.Value))
                {
                    nameMatch.Value = true;
                    Fsm.Event(nameMatchEvent);
                }
                else
                {
                    nameMatch.Value = false;
                    Fsm.Event(nameDoNotMatchEvent);
                }
            }
        }
Exemplo n.º 11
0
    // Update is called once per frame
    void Update()
    {
        CurrentTime = Time.time;

        AnimatorStateInfo      info  = anim.GetCurrentAnimatorStateInfo(0); //현재 애니메이션 상태
        AnimatorTransitionInfo info2 = anim.GetAnimatorTransitionInfo(0);   //현재 트랜지션 상태

        //anim.runtimeAnimatorController = Resources.Load("") as RuntimeAnimatorController; //애니메이터 변경

        //점프
        if (agent.isOnOffMeshLink)
        {
            if (!jump)
            {
                offMeshLinkData = agent.currentOffMeshLinkData;
                jump            = true;

                jumpStartPos = transform.position;

                Vector3 dirToJump = offMeshLinkData.endPos - jumpStartPos;

                jumpDistance = dirToJump.magnitude;

                jumpTotalTime = jumpDistance / jumpSpeed;

                jumpDeltaTime = 0.0f;

                dirToJump.y = 0.0f;
                dirToJump  *= 1.0f / jumpDistance;

                agent.isStopped = true;

                if (Vector3.Distance(offMeshLinkData.startPos, GameObject.Find("Sofa").transform.position) <= 0.2f)
                {
                    anim.SetBool("JumpDown", true);
                    anim.SetBool("Jump", false);
                }
                else if (Vector3.Distance(offMeshLinkData.startPos, GameObject.Find("Plane (1)").transform.position) <= 0.3f)
                {
                    anim.SetBool("Jump", true);
                    anim.SetBool("JumpDown", false);
                }
            }
            else
            {
                jumpDeltaTime += Time.deltaTime;
                float factor = jumpDeltaTime / jumpTotalTime;
                bool  isOffMeshLinkComplete = false;

                if (anim.GetBool("Jump"))
                {
                    if (factor > 0.5f)
                    {
                        isOffMeshLinkComplete = true;
                    }
                }
                else if (anim.GetBool("JumpDown"))
                {
                    if (factor > 1.0f)
                    {
                        isOffMeshLinkComplete = true;
                    }
                }

                if (isOffMeshLinkComplete)
                {
                    transform.position = offMeshLinkData.endPos;

                    agent.CompleteOffMeshLink();
                    agent.isStopped = false;

                    jump = false;

                    anim.SetBool("Jump", false);
                    anim.SetBool("JumpDown", false);
                }
                else
                {
                    Vector3    pos    = Vector3.Lerp(jumpStartPos, offMeshLinkData.endPos, factor);
                    GameObject target = null;
                    Vector3    vec    = Vector3.zero;
                    if (anim.GetBool("JumpDown"))
                    {
                        jumpHeight = -0.8f;
                        pos.y     -= Mathf.Sin(Mathf.PI * factor) * jumpHeight;
                        target     = GameObject.Find("Plane (1)");
                    }
                    else if (anim.GetBool("Jump"))
                    {
                        jumpHeight = 0.8f;
                        pos.y     += Mathf.Sin(Mathf.PI * factor) * jumpHeight;
                        target     = GameObject.Find("Sofa");
                    }
                    transform.position = pos;
                    vec = (target.transform.position - transform.position).normalized;
                    Quaternion toQuaternion = Quaternion.LookRotation(vec);
                    transform.rotation = Quaternion.Slerp(transform.rotation, toQuaternion, 3.0f * Time.deltaTime);
                }
            }
        }

        if (hungry >= 0.02f)
        {
            hungry -= 0.02f;
        }

        //5초마다 호감도 1씩 상승
        if (CurrentTime - FriendlyTimer > 5.0f)
        {
            if (friendly < 100.0f)
            {
                friendly += 1.0f;
            }
            if (tired <= 98.0f)
            {
                tired += 2.0f;
            }
            if (hungry <= 5.0f)
            {
                if (friendly >= 3.0f)
                {
                    friendly -= 3.0f;
                }
            }
            FriendlyTimer = Time.time;
        }

        KinectManager kinectManager = KinectManager.Instance;
        bool          ready         = Server.readyToUser;

        //유저입력대기
        if (anim.GetBool("UserInput"))
        {
            agent.SetDestination(new Vector3(1.0f, 1.17f, -0.2f));
            if (Vector3.Distance(new Vector3(1.0f, 1.17f, -0.2f), transform.position) <= 0.3f)
            {
                agent.isStopped = true;
                transform.LookAt(new Vector3(GameObject.Find("Main Camera").transform.position.x, GameObject.Find("Main Camera").transform.position.y - 2.0f, GameObject.Find("Main Camera").transform.position.z));
                anim.SetBool("Run", false);
                anim.SetBool("Walk", false);
                anim.SetBool("Sleep", false);
                anim.SetBool("Play", false);
                anim.SetBool("Wash", false);
                if (hungry <= 10 && !info.IsName("D_chodai"))
                {
                    anim.SetBool("B_idle", false);
                    anim.SetBool("Hungry", true);
                    anim.SetTrigger("Chodai");
                }
                else if (hungry > 10 && !info.IsName("B_idle"))
                {
                    anim.SetTrigger("B_idle");
                    anim.SetBool("Hungry", false);
                }
                GameObject.Find("Sofa").GetComponent <OffMeshLink>().activated = false;
            }
            else if (Vector3.Distance(new Vector3(1.0f, 1.17f, -0.2f), transform.position) > 0.3f)
            {
                anim.SetBool("Run", true);
            }
            if (CurrentTime - UserInputTime >= 60.0f && UserInputTime != 0.0f) //&& !kinectManager.IsUserDetected()
            {
                anim.SetBool("UserInput", false);
                anim.SetBool("B_idle", false);
                anim.SetBool("Hungry", false);

                RandomBehaviorSelector();
                UserInputTime = 0.0f;
                GameObject.Find("Sofa").GetComponent <OffMeshLink>().activated = true;
            }
            if (tired >= 90.0f && CurrentTime - UserInputTime >= 80.0f && UserInputTime != 0.0f)
            {
                friendly -= 0.05f;
            }
        }
        else
        {
            if (select_behavior == (int)CatState.sleep)
            {
                YarnBall.GetComponent <NavMeshObstacle>().enabled = true;
                Scratter.GetComponent <NavMeshObstacle>().enabled = true;
                if (!agent.pathPending)
                {
                    anim.SetBool("Sleep", true);
                    anim.SetBool("Run", false);
                    anim.SetBool("Walk", false);
                    anim.SetBool("Play", false);
                }
                if (CurrentTime - AnimationTime > 10.0f)
                {
                    anim.SetBool("Sleep", false);
                    RandomBehaviorSelector();
                }
            }
            else if (select_behavior == (int)CatState.idle)
            {
                YarnBall.GetComponent <NavMeshObstacle>().enabled = true;
                Scratter.GetComponent <NavMeshObstacle>().enabled = true;
                if (!agent.pathPending)
                {
                    anim.SetBool("Run", false);
                    anim.SetBool("Walk", false);
                    anim.SetBool("Play", false);
                    anim.SetBool("Sleep", false);
                }
                if (CurrentTime - AnimationTime > 5.0f)
                {
                    RandomBehaviorSelector();
                    agent.SetDestination(new Vector3(Random.Range(-600, 700) * 0.01f, 0, Random.Range(-200, 500) * 0.01f));

                    anim.SetBool("Run", false);
                    anim.SetBool("Walk", false);
                    anim.SetBool("Play", false);
                    anim.SetBool("Sleep", false);
                }
            }
            else if (select_behavior == (int)CatState.wash)
            {
                YarnBall.GetComponent <NavMeshObstacle>().enabled = true;
                Scratter.GetComponent <NavMeshObstacle>().enabled = true;
                agent.velocity  = new Vector3(0, 0, 0);
                agent.speed     = 0;
                agent.isStopped = true;
                anim.SetBool("Run", false);
                anim.SetBool("Walk", false);
                anim.SetBool("Play", false);
                anim.SetBool("Sleep", false);
                anim.SetBool("Wash", true);
            }
            else if (select_behavior == (int)CatState.walk)
            {
                YarnBall.GetComponent <NavMeshObstacle>().enabled = true;
                Scratter.GetComponent <NavMeshObstacle>().enabled = true;

                if (!agent.pathPending)
                {
                    if (agent.remainingDistance <= 0.1f)
                    {
                        RandomBehaviorSelector();
                        agent.SetDestination(new Vector3(Random.Range(-600, 700) * 0.01f, 0, Random.Range(-200, 500) * 0.01f));
                    }
                    agent.speed = 1;
                    anim.SetBool("Run", false);
                    anim.SetBool("Walk", true);
                    anim.SetBool("Play", false);
                    anim.SetBool("Sleep", false);
                }
            }
            else if (select_behavior == (int)CatState.run)
            {
                YarnBall.GetComponent <NavMeshObstacle>().enabled = true;
                Scratter.GetComponent <NavMeshObstacle>().enabled = true;
                if (!agent.pathPending)
                {
                    if (agent.remainingDistance <= 0.1f)
                    {
                        RandomBehaviorSelector();
                        agent.SetDestination(new Vector3(Random.Range(-600, 700) * 0.01f, 0, Random.Range(-200, 500) * 0.01f));
                    }
                    agent.speed = 2;
                    anim.SetBool("Run", true);
                    anim.SetBool("Walk", false);
                    anim.SetBool("Play", false);
                    anim.SetBool("Sleep", false);
                }
            }
            else if (select_behavior == (int)CatState.play)
            {
                agent.SetDestination(YarnBall.transform.position);
                YarnBall.GetComponent <NavMeshObstacle>().enabled = false;
                if (onTriggerYarn)
                {
                    anim.SetBool("Run", false);
                    agent.velocity  = new Vector3(0, 0, 0);
                    agent.speed     = 0;
                    agent.isStopped = true;
                    anim.SetBool("Play", true);
                }
                else
                {
                    if (!agent.pathPending)
                    {
                        agent.speed = 2;
                        anim.SetBool("Run", true);
                        anim.SetBool("Walk", false);
                        anim.SetBool("Play", false);
                        anim.SetBool("Sleep", false);
                    }
                }
                if (info.IsName("A_punch_R") && info.normalizedTime >= 0.4)
                {
                    YarnBall.transform.Translate(-transform.right * 0.5f * Time.deltaTime);
                    YarnBall.transform.Rotate(transform.right * -200.0f * Time.deltaTime);
                }
                if (CurrentTime - PlayTime >= 2.5f && PlayTime != 0.0f)
                {
                    anim.SetBool("Play", false);
                    RandomBehaviorSelector();
                    agent.SetDestination(new Vector3(Random.Range(-600, 700) * 0.01f, 0, Random.Range(-200, 500) * 0.01f));
                    YarnBall.GetComponent <NavMeshObstacle>().enabled = true;
                    PlayTime      = 0.0f;
                    onTriggerYarn = false;
                }
            }
            else //if(select_behavior == (int)CatState.pole)
            {
                agent.SetDestination(Scratter.transform.position);
                Scratter.GetComponent <NavMeshObstacle>().enabled = false;

                if (onTriggerScratter)
                {
                    anim.SetBool("Run", false);
                    agent.velocity  = new Vector3(0, 0, 0);
                    agent.speed     = 0;
                    agent.isStopped = true;
                    anim.SetBool("Polling", true);
                    Vector3    vec          = (Scratter.transform.position - transform.position).normalized;
                    Quaternion toQuaternion = Quaternion.LookRotation(vec);
                    transform.rotation = Quaternion.Slerp(transform.rotation, toQuaternion, 3.0f * Time.deltaTime);
                }
                else
                {
                    if (!agent.pathPending)
                    {
                        agent.speed = 2;
                        anim.SetBool("Run", true);
                        anim.SetBool("Walk", false);
                        anim.SetBool("Play", false);
                        anim.SetBool("Sleep", false);
                    }
                }
                if (CurrentTime - PlayTime >= 10.0f && PlayTime != 0.0f)
                {
                    anim.SetBool("Polling", false);
                    RandomBehaviorSelector();
                    agent.SetDestination(new Vector3(Random.Range(-600, 700) * 0.01f, 0, Random.Range(-200, 500) * 0.01f));
                    PlayTime          = 0.0f;
                    onTriggerScratter = false;
                }
            }

            if ((info.IsName("A_walk") || info.IsName("A_run")) && agent.remainingDistance <= 0.1f)
            {
                if (!agent.pathPending)
                {
                    RandomBehaviorSelector();
                    agent.SetDestination(new Vector3(Random.Range(-600, 700) * 0.01f, Random.Range(0, 200) * 0.01f, Random.Range(-200, 500) * 0.01f));
                }
            }
        }

        if (info.IsName("B_idle"))
        {
            agent.isStopped = true;
        }

        if (info2.IsName("A_pole_loop -> A_pole_end"))
        {
            Scratter.GetComponent <NavMeshObstacle>().enabled = true;
        }

        if (info2.IsName("B_idle -> BtoA") || info2.IsName("A_eat -> A_idle") || info2.IsName("parts_ear_stand -> A_idle") || info2.IsName("CtoA -> A_idle"))
        {
            RandomBehaviorSelector();
            GameObject.Find("Sofa").GetComponent <OffMeshLink>().activated = true;
        }

        if (info2.IsName("AnyState -> B_idle"))
        {
            if (UserInputTime == 0.0f)
            {
                UserInputTime = Time.time;
            }
        }

        if (info.IsName("A_idle") || info.IsName("C_sleep"))
        {
            emo.SetActive(false);
            food.SetActive(false);
            agent.speed     = 0;
            agent.velocity  = new Vector3(0, 0, 0);
            agent.isStopped = true;
            if (info.IsName("A_idle") && tired >= 0.05f)
            {
                tired -= 0.05f;
            }
            if (info.IsName("C_sleep") && tired >= 0.01f)
            {
                tired -= 0.01f;
            }
        }

        if (info.IsName("A_walk") || info.IsName("A_run"))
        {
            emo.SetActive(false);
            food.SetActive(false);
            agent.speed     = 1;
            agent.isStopped = false;
            if (jump)
            {
                jump = false;
            }
            if (info.IsName("A_walk") && tired <= 99.995f)
            {
                tired += 0.005f;
            }
            if (info.IsName("A_run") && tired <= 99.99f)
            {
                tired += 0.01f;
            }
        }

        if (info.IsName("A_punch_R") || info.IsName("A_pole_loop"))
        {
            if (info.IsName("A_run") && tired >= 99.97f)
            {
                tired += 0.03f;
            }
        }
        if (info.IsName("B_wash") || info.IsName("B_wash_b") || info.IsName("B_picks"))
        {
            if (tired >= 0.03f)
            {
                tired -= 0.03f;
            }
        }
        if (info.IsName("A_jump_down") && transform.position.y <= 0.05f)
        {
            anim.SetBool("JumpDown", false);
        }

        if (info2.IsName("C_idle -> C_sleep") || info2.IsName("A_walk -> A_idle") || info2.IsName("A_run -> A_idle") || info2.IsName("C_idle -> A_idle"))
        {
            AnimationTime = Time.time;
        }

        if (info2.IsName("A_idle -> A_punch_R") || info2.IsName("AnyState -> A_pole_start"))
        {
            PlayTime = Time.time;
        }

        if (info2.IsName("B_picks -> B_idle 0"))
        {
            anim.SetBool("Wash", false);
            RandomBehaviorSelector();
        }

        if (info2.IsName("AnyState -> parts_ear_down") || info2.IsName("D_idle -> D_chodai"))
        {
            ResponseTime = Time.time;
        }

        if (info.IsName("parts_ear_stand") || info2.IsName("D_chodai"))
        {
            if (CurrentTime - ResponseTime >= 5.0f)
            {
                anim.SetBool("EarDown", false);
                anim.SetBool("EarUp", false);
                anim.SetBool("Hungry", false);
            }
        }

        // 저장
        PlayerPrefs.SetFloat("Friendly", friendly);
        PlayerPrefs.SetFloat("Hungry", hungry);
        PlayerPrefs.SetFloat("Tired", tired);
    }
Exemplo n.º 12
0
    public override void Update(PlayerController player)
    {
        AnimatorStateInfo      animState = player.Anim.GetCurrentAnimatorStateInfo(0);
        AnimatorTransitionInfo transInfo = player.Anim.GetAnimatorTransitionInfo(0);

        right = Input.GetAxisRaw(player.Inputf.horizontalAxis);

        if (isInCornering || isOutCornering)
        {
            if (animState.IsName("InCornerLeft") || animState.IsName("CornerLeft") ||
                animState.IsName("CornerRight") || animState.IsName("InCornerRight"))
            {
                player.UseRootMotion = true;

                MatchTargetWeightMask mask = new MatchTargetWeightMask(Vector3.one, 1f);
                player.Anim.MatchTarget(cornerTargetPosition, cornerTargetRotation, AvatarTarget.Root, mask, 0f, 1f);

                return;
            }
            else if (animState.IsName("HangLoop"))
            {
                isOutCornering = isInCornering = false;

                player.UseRootMotion = true;
            }
            else
            {
                return;
            }
        }
        else if (isClimbingUp)
        {
            if (animState.IsName("Idle") || transInfo.IsName("ClimbUp -> Idle"))
            {
                player.StateMachine.GoToState <Locomotion>();
            }

            return;
        }

        if (Input.GetKeyDown(player.Inputf.crouch))
        {
            LetGo(player);
            return;
        }

        // Adjustment for moving platforms
        RaycastHit hit;

        if (Physics.Raycast(player.transform.position + Vector3.up * (player.HangUpOffset - 0.1f), player.transform.forward, out hit, 1f, ~(1 << 8), QueryTriggerInteraction.Ignore))
        {
            if (hit.collider.CompareTag("MovingPlatform"))
            {
                MovingPlatform moving = hit.collider.GetComponent <MovingPlatform>();

                moving.AttachTransform(player.transform);
            }
        }

        if (right != 0f)
        {
            LookForCorners(player);
        }

        AdjustPosition(player);

        player.Anim.SetFloat("Right", right);

        player.Anim.SetBool("isOutCorner", isOutCornering);
        player.Anim.SetBool("isInCorner", isInCornering);

        if (Input.GetKey(player.Inputf.jump) && animState.IsName("HangLoop"))
        {
            if (ledgeDetector.CanClimbUp(player.transform.position, player.transform.forward))
            {
                ClimbUp(player);
            }
        }
    }
Exemplo n.º 13
0
    public override void Update(PlayerController player)
    {
        AnimatorStateInfo      animState = player.Anim.GetCurrentAnimatorStateInfo(0);
        AnimatorTransitionInfo transInfo = player.Anim.GetAnimatorTransitionInfo(0);

        // Used to determine if forward or up stand jump
        float targetSpeed = UMath.GetHorizontalMag(player.RawTargetVector());

        player.Anim.SetFloat("TargetSpeed", targetSpeed);

        bool isDive = player.Anim.GetBool("isDive");

        if (!player.AutoLedgeTarget && Input.GetKey(player.Inputf.action) && !isDive)
        {
            isGrabbing = true;
        }

        // Allows player to smoothly turn round during stand jump
        if ((animState.IsName("Still_Compress_Forward") || animState.IsName("Compress")) && !noRotate && !hasJumped)
        {
            player.MoveGrounded(1f);
            player.RotateToVelocityGround();
        }

        if (Input.GetKey(player.Inputf.crouch) && !hasJumped)
        {
            player.Anim.SetBool("isDive", true);
            isDive = true;
        }

        bool isRunJump   = animState.IsName("RunJump") || animState.IsName("RunJumpM") || animState.IsName("Dive");
        bool isStandJump = animState.IsName("StandJump") || transInfo.IsName("Still_Compress_Forward -> StandJump");
        bool isJumpUp    = animState.IsName("JumpUp");

        if ((isRunJump || isStandJump || isJumpUp) && !hasJumped)
        {
            player.UseRootMotion = false;

            float zVel = isRunJump ? player.RunJumpVel
                : isStandJump ? player.StandJumpVel
                : 0.1f;
            float yVel = player.JumpYVel;

            // Snaps forward standing jumps to right direction (more responsive)
            if (isStandJump && !noRotate)
            {
                Vector3 targetJumpDir = player.RawTargetVector(1f, true);

                if (targetJumpDir.sqrMagnitude != 0f)  // Stops Lara snapping to (0,0,1)
                {
                    Quaternion rotationTarget = Quaternion.LookRotation(targetJumpDir, Vector3.up);
                    player.transform.rotation = rotationTarget;
                }
            }

            // Checks for ledges
            if (player.AutoLedgeTarget && !isDive)
            {
                Vector3 autoGrabCastStart = player.transform.position + Vector3.down * 2.5f;
                float   autoGrabMaxHeight = 2.5f + player.JumpHeight + player.GrabUpOffset;

                ledgesDetected = ledgeDetector.FindLedgeJump(autoGrabCastStart, player.transform.forward, 6.2f, autoGrabMaxHeight, out ledgeInfo, player);

                if (ledgesDetected && TryReachLedge(player, zVel, ref yVel))
                {
                    return;  // Can reach ledge - ignore code left in this state
                }
                else
                {
                    // Check for monkeys and poles
                    Vector3 start = player.transform.position + Vector3.up * player.CharControl.height;
                    Vector3 dir   = isJumpUp ? Vector3.up : player.transform.forward + Vector3.up;
                    ledgesDetected = ledgeDetector.FindAboveHead(start, dir, 4f, out ledgeInfo);

                    if (ledgesDetected)
                    {
                        player.StateMachine.GoToState <AutoGrabbing>(ledgeInfo);
                        return;
                    }
                }
            }

            player.ImpulseVelocity(player.transform.forward * zVel + Vector3.up * yVel);

            hasJumped = true;
        }
        else if (hasJumped)
        {
            if (isGrabbing)
            {
                player.StateMachine.GoToState <Grabbing>();
                return;
            }
            else
            {
                player.StateMachine.GoToState <InAir>();
                return;
            }
        }
    }
Exemplo n.º 14
0
        protected override bool OnCheck()
        {
            AnimatorTransitionInfo _info = agent.GetAnimatorTransitionInfo(layerIndex.value);

            return(_info.IsName(transitionName.value));
        }
Exemplo n.º 15
0
    public override void Update(PlayerController player)
    {
        AnimatorStateInfo      animState = player.Anim.GetCurrentAnimatorStateInfo(0);
        AnimatorTransitionInfo transInfo = player.Anim.GetAnimatorTransitionInfo(0);

        right = Input.GetAxisRaw(player.Inputf.horizontalAxis);

        if (isInCornering || isOutCornering)
        {
            if (animState.IsName("InCornerLeft") || animState.IsName("CornerLeft") ||
                animState.IsName("CornerRight") || animState.IsName("InCornerRight"))
            {
                player.UseRootMotion = true;

                MatchTargetWeightMask mask = new MatchTargetWeightMask(Vector3.one, 1f);
                player.Anim.MatchTarget(cornerTargetPosition, cornerTargetRotation, AvatarTarget.Root, mask, 0f, 1f);

                return;
            }
            else if (animState.IsName("HangLoop"))
            {
                isOutCornering = isInCornering = false;

                player.UseRootMotion = true;
            }
            else
            {
                return;
            }
        }
        else if (isClimbingUp)
        {
            if (animState.IsName("Idle") || transInfo.IsName("ClimbUp -> Idle"))
            {
                player.StateMachine.GoToState <Locomotion>();
            }

            return;
        }

        if (Input.GetKeyDown(player.Inputf.crouch))
        {
            LetGo(player);
            return;
        }

        AdjustPosition(player);

        if (right != 0f)
        {
            LookForCorners(player);
        }

        player.Anim.SetFloat("Right", right);

        player.Anim.SetBool("isOutCorner", isOutCornering);
        player.Anim.SetBool("isInCorner", isInCornering);

        // Test for climbing up key hold times
        if (animState.IsName("HangLoop"))
        {
            if (Input.GetKey(player.Inputf.jump) && jumpHeldFor < HANDSTAND_HOLD_TIME)
            {
                jumpHeldFor += Time.deltaTime;
            }
            else if (Input.GetKeyUp(player.Inputf.jump) || jumpHeldFor >= HANDSTAND_HOLD_TIME)
            {
                Vector3 tryClimbTo = ledgeInfo.Point + player.transform.forward * player.CharControl.radius;
                if (UMath.CanFitInSpace(tryClimbTo, player.CharControl.height, player.CharControl.radius))
                {
                    ClimbUp(player);
                }
            }
        }
    }