private void RootMotionMovement()
        {
            _stateInfo = _animator.GetCurrentAnimatorStateInfo(0);
            _transInfo = _animator.GetAnimatorTransitionInfo(0);

            StickToWorldspace();

            float speed = _input.sqrMagnitude * (_running ? runSpeed : walkSpeed);

            _animator.SetFloat(speedFloat, speed, speedDamp, Time.deltaTime);

            if (speed < speedThreshold)
            {
                _direction = 0;
            }

            _animator.SetFloat(directionFloat, _direction, directionDamp, Time.deltaTime);

            if (!IsInPivot())
            {
                if (speed > speedThreshold)
                {
                    _animator.SetFloat(angleFloat, _angle);
                }
                else
                {
                    _animator.SetFloat(directionFloat, 0);
                    _animator.SetFloat(angleFloat, 0);
                }
            }
        }
Exemplo n.º 2
0
        bool CheckAnimStateChanged(out int stateHash, out float normalizedTime, int layerId)
        {
            stateHash      = 0;
            normalizedTime = 0;

            if (Animator.IsInTransition(layerId))
            {
                AnimatorTransitionInfo tt = Animator.GetAnimatorTransitionInfo(layerId);
                if (tt.fullPathHash != transitionHash[layerId])
                {
                    // first time in this transition
                    transitionHash[layerId] = tt.fullPathHash;
                    animationHash[layerId]  = 0;
                    return(true);
                }
                return(false);
            }

            AnimatorStateInfo st = Animator.GetCurrentAnimatorStateInfo(layerId);

            if (st.fullPathHash != animationHash[layerId])
            {
                // first time in this animation state
                if (animationHash[layerId] != 0)
                {
                    // came from another animation directly - from Play()
                    stateHash      = st.fullPathHash;
                    normalizedTime = st.normalizedTime;
                }
                transitionHash[layerId] = 0;
                animationHash[layerId]  = st.fullPathHash;
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        // 检查 是否处于对应的 状态
        bool CheckStateAndTransition(string name, int layerIndex = 0)
        {
            AnimatorStateInfo      animatorState      = animator.GetCurrentAnimatorStateInfo(layerIndex);
            AnimatorTransitionInfo animatorTransition = animator.GetAnimatorTransitionInfo(layerIndex);

            return(animatorState.IsTag(name) || animatorTransition.IsUserName(name));
        }
Exemplo n.º 4
0
                public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
                {
                    CacheAnimator(animator);

                    float blendTime = 0.0f;

                    if (animator.IsInTransition(layerIndex))
                    {
                        AnimatorTransitionInfo trans = animator.GetAnimatorTransitionInfo(layerIndex);

                        switch (trans.durationUnit)
                        {
                        case DurationUnit.Fixed:
                        {
                            blendTime = trans.duration;
                        }
                        break;

                        case DurationUnit.Normalized:
                        {
                            Animation animation = _animator.GetChannelPrimaryAnimation(layerIndex);
                            blendTime = trans.duration * (animation != null ? animation.Duration : 0.0f);
                        }
                        break;
                        }
                    }

                    StartAnimation(stateInfo, layerIndex, blendTime);
                }
Exemplo n.º 5
0
        private bool CheckAnimStateChanged(out int stateHash, out float normalizedTime)
        {
            stateHash      = 0;
            normalizedTime = 0;

            if (animator.IsInTransition(0))
            {
                AnimatorTransitionInfo animationTransitionInfo = animator.GetAnimatorTransitionInfo(0);
                if (animationTransitionInfo.fullPathHash != transitionHash)
                {
                    // first time in this transition
                    transitionHash = animationTransitionInfo.fullPathHash;
                    animationHash  = 0;
                    return(true);
                }
                return(false);
            }

            AnimatorStateInfo animationSateInfo = animator.GetCurrentAnimatorStateInfo(0);

            if (animationSateInfo.fullPathHash != animationHash)
            {
                // first time in this animation state
                if (animationHash != 0)
                {
                    // came from another animation directly - from Play()
                    stateHash      = animationSateInfo.fullPathHash;
                    normalizedTime = animationSateInfo.normalizedTime;
                }
                transitionHash = 0;
                animationHash  = animationSateInfo.fullPathHash;
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
    public float GetWeight(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        float stateWeight = 0f;
        AnimatorTransitionInfo transition = animator.GetAnimatorTransitionInfo(layerIndex);

        bool currentIsThis = animator.GetCurrentAnimatorStateInfo(layerIndex).shortNameHash.Equals(stateInfo.shortNameHash);
        bool nextIsThis    = animator.GetNextAnimatorStateInfo(layerIndex).shortNameHash.Equals(stateInfo.shortNameHash);
        bool inTransition  = animator.IsInTransition(layerIndex);

        bool inControl = (currentIsThis && !inTransition) || nextIsThis;

        if (currentIsThis && !inTransition)
        {
            stateWeight = 1f;
        }
        else if (currentIsThis && inTransition)
        {
            stateWeight = 1f - transition.normalizedTime;
        }
        else if (nextIsThis && inTransition)
        {
            stateWeight = transition.normalizedTime;
        }
        else
        {
            stateWeight = 0f;
        }
        return(stateWeight);
    }
Exemplo n.º 7
0
    void Update()
    {
        _stateInfo = _animator.GetCurrentAnimatorStateInfo(0);
        _transInfo = _animator.GetAnimatorTransitionInfo(0);

        _input.x = Input.GetAxis("Horizontal");
        _input.y = Input.GetAxis("Vertical");

        StickToWorldspace();

        float speed = _input.sqrMagnitude;

        _animator.SetFloat(speedFloat, speed, speedDamp, Time.deltaTime);

        if (speed < speedThreshold)
        {
            _direction = 0;
        }

        _animator.SetFloat(directionFloat, _direction, directionDamp, Time.deltaTime);

        if (!IsInPivot())
        {
            if (speed > speedThreshold)
            {
                _animator.SetFloat(angleFloat, _angle);
            }
            else
            {
                _animator.SetFloat(directionFloat, 0);
                _animator.SetFloat(angleFloat, 0);
            }
        }
    }
Exemplo n.º 8
0
    // Update is called once per frame
    void Update()
    {
        if (animator && gameCam.CamState != ThirdPersonCamera.CamStates.FirstPerson)
        {
            stateInfo = animator.GetCurrentAnimatorStateInfo(0);
            transInfo = animator.GetAnimatorTransitionInfo(0);

            leftX = Input.GetAxis("Horizontal");
            leftY = Input.GetAxis("Vertical");

            charAngle = 0f;
            direction = 0f;

            StickToWorldspace(this.transform, gameCam.transform, ref direction, ref speed, ref charAngle, IsInPivot());

            animator.SetFloat("Speed", speed, speedDampTime, Time.deltaTime);
            animator.SetFloat("Direction", direction, directionDampTime, Time.deltaTime);

            if (speed > LocomotionThreshold)
            {
                if (!IsInPivot())
                {
                    Animator.SetFloat("Angle", charAngle);
                }

                if (speed < LocomotionThreshold && Mathf.Abs(leftX) < 0.05f)
                {
                    animator.SetFloat("Direction", 0f);
                    animator.SetFloat("Angle", 0f);
                }
            }
        }
    }
Exemplo n.º 9
0
        private bool CheckAnimStateChanged(out int stateHash, out float normalizedTime)
        {
            stateHash      = 0;
            normalizedTime = 0f;
            if (m_Animator.IsInTransition(0))
            {
                AnimatorTransitionInfo animatorTransitionInfo = m_Animator.GetAnimatorTransitionInfo(0);
                if (animatorTransitionInfo.fullPathHash != m_TransitionHash)
                {
                    m_TransitionHash = animatorTransitionInfo.fullPathHash;
                    m_AnimationHash  = 0;
                    return(true);
                }
                return(false);
            }
            AnimatorStateInfo currentAnimatorStateInfo = m_Animator.GetCurrentAnimatorStateInfo(0);

            if (currentAnimatorStateInfo.fullPathHash != m_AnimationHash)
            {
                if (m_AnimationHash != 0)
                {
                    stateHash      = currentAnimatorStateInfo.fullPathHash;
                    normalizedTime = currentAnimatorStateInfo.normalizedTime;
                }
                m_TransitionHash = 0;
                m_AnimationHash  = currentAnimatorStateInfo.fullPathHash;
                return(true);
            }
            return(false);
        }
Exemplo n.º 10
0
        bool CheckAnimStateChanged(out int stateHash, out float normalizedTime)
        {
            stateHash      = 0;
            normalizedTime = 0;

            if (m_Animator.IsInTransition(0))
            {
                AnimatorTransitionInfo tt = m_Animator.GetAnimatorTransitionInfo(0);
                if (tt.fullPathHash != m_TransitionHash)
                {
                    // first time in this transition
                    m_TransitionHash = tt.fullPathHash;
                    m_AnimationHash  = 0;
                    return(true);
                }
                return(false);
            }

            AnimatorStateInfo st = m_Animator.GetCurrentAnimatorStateInfo(0);

            if (st.fullPathHash != m_AnimationHash)
            {
                // first time in this animation state
                if (m_AnimationHash != 0)
                {
                    // came from another animation directly - from Play()
                    stateHash      = st.fullPathHash;
                    normalizedTime = st.normalizedTime;
                }
                m_TransitionHash = 0;
                m_AnimationHash  = st.fullPathHash;
                return(true);
            }
            return(false);
        }
Exemplo n.º 11
0
        private bool CheckAnimStateChanged(out int stateHash, out float normalizedTime)
        {
            stateHash      = 0;
            normalizedTime = 0.0f;
            if (this.m_Animator.IsInTransition(0))
            {
                AnimatorTransitionInfo animatorTransitionInfo = this.m_Animator.GetAnimatorTransitionInfo(0);
                if (animatorTransitionInfo.fullPathHash == this.m_TransitionHash)
                {
                    return(false);
                }
                this.m_TransitionHash = animatorTransitionInfo.fullPathHash;
                this.m_AnimationHash  = 0;
                return(true);
            }
            AnimatorStateInfo animatorStateInfo = this.m_Animator.GetCurrentAnimatorStateInfo(0);

            if (animatorStateInfo.fullPathHash == this.m_AnimationHash)
            {
                return(false);
            }
            if (this.m_AnimationHash != 0)
            {
                stateHash      = animatorStateInfo.fullPathHash;
                normalizedTime = animatorStateInfo.normalizedTime;
            }
            this.m_TransitionHash = 0;
            this.m_AnimationHash  = animatorStateInfo.fullPathHash;
            return(true);
        }
    void checkTurns(AnimatorTransitionInfo transInfo)
    {
        bool left_to_stand   = (transInfo.nameHash == Animator.StringToHash("TurnLeft -> Stand"));
        bool left_to_crouch  = (transInfo.nameHash == Animator.StringToHash("CrouchTurnLeft -> Crouch"));
        bool right_to_stand  = (transInfo.nameHash == Animator.StringToHash("TurnRight -> Stand"));
        bool right_to_crouch = (transInfo.nameHash == Animator.StringToHash("CrouchTurnRight -> Crouch"));

        // Check if we have finished the rotation
        if ((left_to_stand) || (left_to_crouch))
        {
            anim.SetBool("turn_left", false);
            if (_turning == true)
            {
                _turning = false;
                _state   = _state + 1;
            }
        }
        if ((right_to_stand) || (right_to_crouch))
        {
            anim.SetBool("turn_right", false);
            if (_turning == true)
            {
                _turning = false;
                _state   = _state + 1;
                fixRotation();
            }
        }
    }
Exemplo n.º 13
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.º 14
0
    void Update()
    {
        //------------------------------------------------------------------------------------------//
        //-----------------------------   ATTACK AND MOVEMENT LOGIC   ------------------------------//
        //------------------------------------------------------------------------------------------//
        if (!Target)
        {
            Target = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform>();
        }

        HasPath            = Physics2D.OverlapCircle(GroundCheck.position, CheckRadius, WhatIsGround);
        DistanceFromPlayer = Vector3.Distance(transform.position, Target.transform.position);

        if (HasPath && DistanceFromPlayer < TrackingRange)
        {
            AnimatorTransitionInfo info = PlayerAnimator.GetAnimatorTransitionInfo(0);
            if (!BreakBetweenAttacks)
            {
                if (DistanceFromPlayer <= AttackRange)
                {
                    AttackHandler();
                }
                if (!IsAttacking && CanMove)
                {
                    transform.position = Vector2.MoveTowards(transform.position, Target.position, Speed * Time.deltaTime);
                }
            }
            else if (DistanceFromPlayer > 1.1f && CanMove)
            {
                transform.position = Vector2.MoveTowards(transform.position, Target.position, Speed * Time.deltaTime);
            }
        }

        MovementAnimationHandler();
    }
Exemplo n.º 15
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;
        }
    }
    // Update is called once per frame
    void Update()
    {
        AnimatorStateInfo      stateInfo = anim.GetCurrentAnimatorStateInfo(0);
        AnimatorTransitionInfo transInfo = anim.GetAnimatorTransitionInfo(0);

        // Wait to start
        if (Time.time - _start_time > startDelay)
        {
            if (scenarioSelection == Scenarios.walking)
            {
                update_walk(stateInfo, transInfo);
            }

            if (scenarioSelection == Scenarios.running)
            {
                update_run(stateInfo, transInfo);
            }

            // Check if we had any turning animation started
            if (_turning)
            {
                checkTurns(transInfo);
            }

            // Check if we have reached our destination forward
            if (_distance_forward > 0)
            {
                checkForward(stateInfo);
            }
        }
    }
Exemplo n.º 17
0
		void GetTransitionInfo()
		{		
			if (_animator!=null)
			{
				AnimatorTransitionInfo _info = _animator.GetAnimatorTransitionInfo(layerIndex.Value);

				if (!name.IsNone)
				{
					name.Value = _animator.GetLayerName(layerIndex.Value);	
				}

				if (!nameHash.IsNone)
				{
					nameHash.Value = _info.nameHash;
				}

				if (!userNameHash.IsNone)
				{
					userNameHash.Value = _info.userNameHash;
				}

				if (!normalizedTime.IsNone)
				{
					normalizedTime.Value = _info.normalizedTime;
				}
			}
		}
Exemplo n.º 18
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.º 19
0
 public void Clear()
 {
     this.m_CurrentState = null;
     this.m_NextState    = null;
     this.m_CurrentStateNormalizedTime = 0f;
     this.m_NextStateNormalizedTime    = 0f;
     this.m_TransitionInfo             = default(AnimatorTransitionInfo);
 }
Exemplo n.º 20
0
 void Start()
 {
     controller         = GetComponent <CharacterController>();
     cam                = Camera.main;
     anim               = GetComponentInChildren <Animator>();
     armsTransitionInfo = anim.GetAnimatorTransitionInfo(1);
     EquipGun(0);
 }
Exemplo n.º 21
0
    static int _CreateAnimatorTransitionInfo(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 0);
        AnimatorTransitionInfo obj = new AnimatorTransitionInfo();

        LuaScriptMgr.PushValue(L, obj);
        return(1);
    }
Exemplo n.º 22
0
 private void UpdateOwnerWithEvents()
 {
     if (base.entity.IsOwner())
     {
         base.state.MecanimSpeed = this.TargetAnimator.speed;
         for (int i = 0; i < this.LayersToSync.Length; i++)
         {
             MecanimLayerConfig mecanimLayerConfig = this.LayersToSync[i];
             if (mecanimLayerConfig.LayerIndex == -1)
             {
                 this.forceLayerIndexSync();
             }
             AnimatorStateInfo animatorStateInfo = this.TargetAnimator.GetCurrentAnimatorStateInfo(mecanimLayerConfig.LayerIndex);
             int fullPathHash = animatorStateInfo.fullPathHash;
             if (this.TargetAnimator.IsInTransition(mecanimLayerConfig.LayerIndex))
             {
                 animatorStateInfo = this.TargetAnimator.GetNextAnimatorStateInfo(mecanimLayerConfig.LayerIndex);
                 AnimatorTransitionInfo animatorTransitionInfo = this.TargetAnimator.GetAnimatorTransitionInfo(mecanimLayerConfig.LayerIndex);
                 float normalizedTime = animatorTransitionInfo.normalizedTime;
                 if (animatorStateInfo.fullPathHash != mecanimLayerConfig.Hash && this.TransitionData.Lookup != null)
                 {
                     int key = fullPathHash - animatorStateInfo.fullPathHash;
                     if (animatorTransitionInfo.anyState)
                     {
                         key = 1111 - animatorStateInfo.fullPathHash;
                     }
                     Dictionary <bool, float> dictionary;
                     if (this.TransitionData.Lookup.TryGetValue(key, out dictionary))
                     {
                         if ((animatorStateInfo.tagHash == this.runHash || animatorStateInfo.tagHash == this.walkHash) && !this.isPlayer)
                         {
                             base.StartCoroutine(this.sendTransitionEventDelayed(animatorStateInfo.fullPathHash, mecanimLayerConfig.LayerIndex, animatorStateInfo.normalizedTime, base.entity, animatorTransitionInfo.anyState, 7));
                         }
                         else
                         {
                             base.StartCoroutine(this.sendTransitionEventDelayed(animatorStateInfo.fullPathHash, mecanimLayerConfig.LayerIndex, animatorStateInfo.normalizedTime, base.entity, animatorTransitionInfo.anyState, 0));
                         }
                     }
                     base.state.MecanimLayerHashes[i] = (mecanimLayerConfig.Hash = animatorStateInfo.fullPathHash);
                     base.state.MecanimLayerTimes[i]  = (mecanimLayerConfig.NormalizedTime = animatorStateInfo.normalizedTime);
                 }
             }
             if (this.setup && this.setup.animControl && animatorStateInfo.tagHash == this.setup.animControl.deathHash)
             {
                 base.state.MecanimLayerHashes[i] = (mecanimLayerConfig.Hash = animatorStateInfo.fullPathHash);
                 base.state.MecanimLayerTimes[i]  = (mecanimLayerConfig.NormalizedTime = animatorStateInfo.normalizedTime);
             }
             if (mecanimLayerConfig.SyncWeight)
             {
                 float layerWeight = this.TargetAnimator.GetLayerWeight(mecanimLayerConfig.LayerIndex);
                 if (layerWeight != mecanimLayerConfig.Weight)
                 {
                     base.state.MecanimLayerWeights[i] = (mecanimLayerConfig.Weight = layerWeight);
                 }
             }
         }
     }
 }
Exemplo n.º 23
0
                public void Update()
                {
                    _weight = _animator.GetLayerWeight(_layer);

                    GameObject eventListener = _animator.gameObject;

                    //Check if we're transitioning - TO DO! transition from state to same state seem broken / cause pops
                    if (_animator.IsInTransition(_layer))
                    {
                        AnimatorStateInfo      previousState  = _animator.GetCurrentAnimatorStateInfo(_layer);
                        AnimatorStateInfo      nextState      = _animator.GetNextAnimatorStateInfo(_layer);
                        AnimatorTransitionInfo transitionInfo = _animator.GetAnimatorTransitionInfo(_layer);

                        //Check current player is playing the next state
                        if (_clipPlayerStates[_mainPlayerIndex] != nextState.shortNameHash)
                        {
                            //If not switch current player index and start animation on player
                            _mainPlayerIndex = 1 - _mainPlayerIndex;
                            _clipPlayerStates[_mainPlayerIndex] = nextState.shortNameHash;

                            AnimatorClipInfo[] nextClips = _animator.GetNextAnimatorClipInfo(_layer);
                            PlayAnimation(nextState, nextClips, _mainPlayerIndex);
                        }

                        //Then check previous player is playing the previous state
                        if (_clipPlayerStates[1 - _mainPlayerIndex] != previousState.shortNameHash)
                        {
                            _clipPlayerStates[1 - _mainPlayerIndex] = previousState.shortNameHash;

                            AnimatorClipInfo[] previousClips = _animator.GetCurrentAnimatorClipInfo(_layer);
                            PlayAnimation(previousState, previousClips, 1 - _mainPlayerIndex);
                        }

                        //Update times
                        _clipPlayers[_mainPlayerIndex].SetNormalizedTime(nextState.normalizedTime, eventListener);
                        _clipPlayers[1 - _mainPlayerIndex].SetNormalizedTime(previousState.normalizedTime, eventListener);
                        _mainAnimationWeight = transitionInfo.normalizedTime;
                    }
                    //Otherwise just update current animation
                    else
                    {
                        AnimatorStateInfo currentState = _animator.GetCurrentAnimatorStateInfo(_layer);

                        if (_clipPlayerStates[_mainPlayerIndex] != currentState.shortNameHash)
                        {
                            _clipPlayerStates[_mainPlayerIndex] = currentState.shortNameHash;
                            AnimatorClipInfo[] currentClips = _animator.GetCurrentAnimatorClipInfo(_layer);
                            PlayAnimation(currentState, currentClips, _mainPlayerIndex);

                            //Stop other player
                            _clipPlayers[1 - _mainPlayerIndex] = new GPUAnimationPlayer();
                        }

                        //Update time
                        _clipPlayers[_mainPlayerIndex].SetNormalizedTime(currentState.normalizedTime, eventListener);
                        _mainAnimationWeight = 1.0f;
                    }
                }
Exemplo n.º 24
0
    /// <summary>
    /// Update is called once per frame.
    /// </summary>
    void Update()
    {
        if (animator && gamecam.CamState != ThirdPersonCamera.CamStates.FirstPerson)
        {
            stateInfo = animator.GetCurrentAnimatorStateInfo(0);
            transInfo = animator.GetAnimatorTransitionInfo(0);

            // Press A to jump
            if (Input.GetButton("Jump"))
            {
                animator.SetBool("Jump", true);
            }
            else
            {
                animator.SetBool("Jump", false);
            }

            // Pull values from controller/keyboard
            leftX = Input.GetAxis("Horizontal");
            leftY = Input.GetAxis("Vertical");

            charAngle = 0f;
            direction = 0f;
            float charSpeed = 0f;

            // Translate controls stick coordinates into world/cam/character space
            StickToWorldspace(this.transform, gamecam.transform, ref direction, ref charSpeed, ref charAngle, IsInPivot());

            // Press B to sprint
            if (Input.GetButton("Sprint"))
            {
                speed = Mathf.Lerp(speed, SPRINT_SPEED, Time.deltaTime);
                gamecam.GetComponent <Camera>().fieldOfView = Mathf.Lerp(gamecam.GetComponent <Camera>().fieldOfView, SPRINT_FOV, fovDampTime * Time.deltaTime);
            }
            else
            {
                speed = charSpeed;
                gamecam.GetComponent <Camera>().fieldOfView = Mathf.Lerp(gamecam.GetComponent <Camera>().fieldOfView, NORMAL_FOV, fovDampTime * Time.deltaTime);
            }

            animator.SetFloat("Speed", speed, speedDampTime, Time.deltaTime);
            animator.SetFloat("Direction", direction, directionDampTime, Time.deltaTime);

            if (speed > LocomotionThreshold)                    // DEAD zone
            {
                if (!IsInPivot())
                {
                    Animator.SetFloat("Angle", charAngle);
                }
            }
            if (speed < LocomotionThreshold && Mathf.Abs(leftX) < 0.05f)                // DEAD zone
            {
                animator.SetFloat("Direction", 0f);
                animator.SetFloat("Angle", 0f);
            }
        }
    }
Exemplo n.º 25
0
    void Update()
    {
        transitionInfo = anim.GetAnimatorTransitionInfo(0);

        if (Input.GetMouseButtonDown(0))
        {
            SetTargetPosition();
        }
    }
Exemplo n.º 26
0
    static int IsUserName(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        AnimatorTransitionInfo obj = LuaScriptMgr.GetNetObject <AnimatorTransitionInfo>(L, 1);
        string arg0 = LuaScriptMgr.GetLuaString(L, 2);
        bool   o    = obj.IsUserName(arg0);

        LuaScriptMgr.Push(L, o);
        return(1);
    }
 //updates animation states
 public void upInfo()
 {
     cstate    = anim.GetCurrentAnimatorStateInfo(0);
     nstate    = anim.GetNextAnimatorStateInfo(0);
     tstate    = anim.GetAnimatorTransitionInfo(0);
     cplaytime = cstate.normalizedTime % 1;
     nplaytime = nstate.normalizedTime % 1;
     //nplaytime = nstate.normalizedTime%1;
     //tplaytime = tstate.normalizedTime%1;
     tchange = anim.IsInTransition(0);
 }
Exemplo n.º 28
0
                private void UpdateAnimator()
                {
                    //Check if we're transitioning - TO DO! transition from state to same state seem broken / cause pops
                    if (_animator.IsInTransition(0))
                    {
                        AnimatorStateInfo      previousState  = _animator.GetCurrentAnimatorStateInfo(0);
                        AnimatorStateInfo      nextState      = _animator.GetNextAnimatorStateInfo(0);
                        AnimatorTransitionInfo transitionInfo = _animator.GetAnimatorTransitionInfo(0);

                        //Check current player is playing the next state
                        if (_clipPlayerStates[_currentPlayerIndex] != nextState.fullPathHash)
                        {
                            //If not switch current player index and start animation on player
                            _currentPlayerIndex = 1 - _currentPlayerIndex;
                            _clipPlayerStates[_currentPlayerIndex] = nextState.fullPathHash;

                            AnimatorClipInfo[] nextClips = _animator.GetNextAnimatorClipInfo(0);
                            PlayAnimation(nextState, nextClips, _currentPlayerIndex);
                        }

                        //Then check previous player is playing the previous state
                        if (_clipPlayerStates[1 - _currentPlayerIndex] != previousState.fullPathHash)
                        {
                            _clipPlayerStates[1 - _currentPlayerIndex] = previousState.fullPathHash;

                            AnimatorClipInfo[] previousClips = _animator.GetCurrentAnimatorClipInfo(0);
                            PlayAnimation(previousState, previousClips, 1 - _currentPlayerIndex);
                        }

                        //Update times
                        _clipPlayers[_currentPlayerIndex].SetNormalizedTime(nextState.normalizedTime);
                        _clipPlayers[1 - _currentPlayerIndex].SetNormalizedTime(previousState.normalizedTime);
                        _currentAnimationWeight = transitionInfo.normalizedTime;
                    }
                    //Otherwise just update current animation
                    else
                    {
                        AnimatorStateInfo currentState = _animator.GetCurrentAnimatorStateInfo(0);

                        if (_clipPlayerStates[_currentPlayerIndex] != currentState.fullPathHash)
                        {
                            _clipPlayerStates[_currentPlayerIndex] = currentState.fullPathHash;
                            AnimatorClipInfo[] currentClips = _animator.GetCurrentAnimatorClipInfo(0);
                            PlayAnimation(currentState, currentClips, _currentPlayerIndex);

                            //Stop other player
                            _clipPlayers[1 - _currentPlayerIndex].Stop();
                        }

                        //Update time
                        _clipPlayers[_currentPlayerIndex].SetNormalizedTime(currentState.normalizedTime);
                        _currentAnimationWeight = 1.0f;
                    }
                }
Exemplo n.º 29
0
    protected virtual void Reset()
    {
        gameObject.AddComponent <LeanSelectable> ();
        gameObject.AddComponent <ModelSelfManager> ();
        gameObject.AddComponent <LeanScale> ().RequiredFingerCount     = 2;
        gameObject.AddComponent <LeanTranslate> ().RequiredFingerCount = 2;
        gameObject.AddComponent <CapsuleCollider> ().height            = 7.0f;
        gameObject.GetComponent <CapsuleCollider> ().radius            = 1.5f;

        Animator animator = gameObject.GetComponent <Animator> ();
        AnimatorTransitionInfo animatorTransitionInfo = animator.GetAnimatorTransitionInfo(0);
    }
Exemplo n.º 30
0
    private void UpdateSwingSpeedMultiplier()
    {
        AnimatorTransitionInfo animatorTransitionInfo   = this.m_Animator.GetAnimatorTransitionInfo(1);
        AnimatorStateInfo      currentAnimatorStateInfo = this.m_Animator.GetCurrentAnimatorStateInfo(1);

        if (animatorTransitionInfo.userNameHash == this.m_NRightSwingToReleaseTransition || animatorTransitionInfo.userNameHash == this.m_NLeftSwingToReleaseTransition || currentAnimatorStateInfo.shortNameHash == this.m_ReleaseStateRight1 || currentAnimatorStateInfo.shortNameHash == this.m_ReleaseStateUp1 || currentAnimatorStateInfo.shortNameHash == this.m_ReleaseStateLeft1)
        {
            this.m_Animator.SetFloat(this.m_NSwingSpeedMultiplier, 0f);
            return;
        }
        this.m_Animator.SetFloat(this.m_NSwingSpeedMultiplier, 1f);
    }