Beispiel #1
0
 private void sendLocomotionStateChangedEvent(LocomotionState state)
 {
     if (broadcastingDisabledEvents == 0)
     {
         networkService.PlayerStateService.SetLocomotionState(state);
     }
 }
 private void changedLocoState(LocomotionState style)
 {
     if (this.PlayerLocoStateChanged != null)
     {
         this.PlayerLocoStateChanged(style);
     }
 }
Beispiel #3
0
            public void ApplyPresentationState(float deltaTime)
            {
                if (m_AnimStateData.charLocoState != m_CurrentAnimationState)
                {
                    var previousState  = m_CurrentAnimationState;
                    var prevController = (int)m_CurrentAnimationState < m_AnimStates.Length ? m_AnimStates[(int)previousState].controller : null;

                    m_CurrentAnimationState = m_AnimStateData.charLocoState;
                    var newController = m_AnimStates[(int)m_CurrentAnimationState].controller;

                    if (newController != prevController)
                    {
                        m_PreviousAnimationState = m_PreviousAnimationState == LocomotionState.MaxValue ? m_CurrentAnimationState : previousState;
                    }
                }

                var interpolationDuration = m_AnimStates[(int)m_CurrentAnimationState].transitionTimes[(int)m_PreviousAnimationState];
                var blendVel = interpolationDuration > 0 ? 1.0f / interpolationDuration : 1.0f / deltaTime;

                m_StateTranstion.Update(m_AnimStates[(int)m_CurrentAnimationState].port, blendVel, deltaTime);

                for (var i = 0; i < (int)LocomotionState.MaxValue; i++)
                {
                    if (m_AnimStates[i].controller != null && m_Mixer.GetInputWeight(m_AnimStates[i].port) > 0f)
                    {
                        m_AnimStates[i].controller.ApplyPresentationState(deltaTime);
                    }
                }
            }
    private void Awake()
    {
        locomotionState = LocomotionState.StandingStill;

        leftLegFootStates  = leftLegEndEffector.GetComponent <FootStates>();
        rightLegFootStates = rightLegEndEffector.GetComponent <FootStates>();
    }
Beispiel #5
0
    public void Tick()
    {
        ////Run initial mover ground check;
        //mover.CheckForGround();
        _characterMover.CheckForGround();

        _state = DetermineControllerState();
        OnStateChange?.Invoke(_state);
        //Debug.Log("STATE:"+_state.ToString());

        //Apply friction and gravity to 'momentum';
        ////HandleMomentum();

        var Jumping = HandleJump();

        Vector3 _velocity = Vector3.zero;

        //If player is grounded or sliding on a slope, extend mover's sensor range;
        //This enables the player to walk up/down stairs and slopes without losing ground contact;
        _characterMover.SetExtendSensorRange(IsGrounded());


        //Set Velocity
        if (IsGrounded())
        {
            _characterMover.SetVelocity(_previousVelocity + _characterMover.GetCurrentGroundAdjustmentVelocity());
            if (_RootMotionDelta.canRotate)
            {
                CalculateCharacterDesiredVector();
                RotateTransform(DesiredCharacterVectorForward);
            }
            SendAnimatorLocomotionCommands(_characterInput.IsRunning());
        }
    }
Beispiel #6
0
 public void BroadcastSetLocomotionState(LocomotionState state)
 {
     if (this.OnLocomotionStateChangedEvent != null)
     {
         this.OnLocomotionStateChangedEvent(state);
     }
 }
Beispiel #7
0
    private void OnEnable()
    {
        if (aiming == null)
        {
            aiming = GetComponent <AimingState>();
        }
        if (locomotion == null)
        {
            locomotion = GetComponent <LocomotionState>();
        }
        if (characterAnimator == null)
        {
            characterAnimator = GetComponent <Animator>();
        }
        if (verticalAimingAnimator == null)
        {
            verticalAimingAnimator = aiming.aimingRigAnimator;
        }
        //targetRotation = Quaternion.LookRotation(aiming.cameraRig.transform.forward, Vector3.up);

        characterAnimator.SetBool("Aiming", false);
        locomotion.cameraBehaviour.gameObject.SetActive(true);

        SendEvent("AIMING_FORWARD");
    }
Beispiel #8
0
    // Use this for initialization
    public override void Start()
    {
        base.Start();

        _locomotionState = LocomotionState.FlyingUp;
        SoundController.PlaySound(SoundType.CrowSpawn);
    }
    private void OnEnable()
    {
        remainingTime = 0.5f;
        if (aiming == null)
        {
            aiming = GetComponent <AimingState>();
        }
        if (locomotion == null)
        {
            locomotion = GetComponent <LocomotionState>();
        }
        if (characterAnimator == null)
        {
            characterAnimator = GetComponent <Animator>();
        }
        if (verticalAimingAnimator == null)
        {
            verticalAimingAnimator = aiming.aimingRigAnimator;
        }

        #region Calculate Target Rotations
        targetRotationHorizontal  = Quaternion.LookRotation(locomotion.ProjectedCameraTransform.forward, Vector3.up);
        targetRotationHorizontal *= Quaternion.Euler(0f, 45f, 0f);

        targetRotationVertical = Mathf.Clamp((locomotion.cameraBehaviour.AngleYZ - Mathf.PI / 2) * Mathf.Rad2Deg, -55f, 55f);
        targetRotationVertical = targetRotationVertical.Remap(-55f, 55f, 0f, 1f);
        aiming.VerticalAngle   = targetRotationVertical;
        #endregion

        characterAnimator.SetBool("Aiming", true);
    }
Beispiel #10
0
 private void OnPlayerLocoStateChanged(LocomotionState state)
 {
     if (this.GenericStateButtonInvoked != null)
     {
         this.GenericStateButtonInvoked(state);
     }
 }
    void UpdateAnimator(Animator animator, LocomotionState locoData)
    {
        LocomotionState.State locoState = locoData.LocoState;
        string aniName = "";

        if (locoState == LocomotionState.State.Idle && !animator.GetCurrentAnimatorStateInfo(0).IsName("idle"))
        {
            aniName = "idle";
        }
        else if (locoState == LocomotionState.State.Run && !animator.GetCurrentAnimatorStateInfo(0).IsName("run"))
        {
            aniName = "run";
        }
        else if (locoState == LocomotionState.State.BeHit && !animator.GetCurrentAnimatorStateInfo(0).IsName("behit"))
        {
            aniName = "behit";
        }
        else if (locoState == LocomotionState.State.Jump && !animator.GetCurrentAnimatorStateInfo(0).IsName("jump"))
        {
            aniName = "jump";
        }
        else if (locoState == LocomotionState.State.DoubleJump && !animator.GetCurrentAnimatorStateInfo(0).IsName("jump2"))
        {
            aniName = "jump2";
        }
        else if (locoState == LocomotionState.State.TrebleJump && !animator.GetCurrentAnimatorStateInfo(0).IsName("jump3"))
        {
            aniName = "jump3";
        }
        else if (locoState == LocomotionState.State.Dead && !animator.GetCurrentAnimatorStateInfo(0).IsName("death"))
        {
            aniName = "death";
            // Debug.Log("TimeEx.ServerTime:"+TimeEx.ServerTime+" startTime:"+locoData.StartTime+" "+((Time.time - locoData.StartTime)));
            // if (Time.time - locoData.StartTime <= 1)
            // {
            // ------animator.Play("death");
            // }
            // else
            // {
            //     //have been dead for a long time
            //     animator.Play("death", 0, 1.0f);
            // }
        }
        if (aniName != "")
        {
            animator.Play(aniName);
            if (aniName == "idle" || aniName == "run")
            {
                var      headTrans    = animator.transform.Find("head");
                Animator headAnimator = null;
                if (headTrans != null)
                {
                    headAnimator = headTrans.GetComponent <Animator>();
                    animator.Play(aniName);
                }
                // Debug.Log("locoState : "+locoState+" headTrans:"+(headTrans!=null));
            }
        }
    }
Beispiel #12
0
 // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     if (locomotion == null)
     {
         locomotion = animator.GetComponent <LocomotionState>();
     }
     animator.SetFloat("ArmsLayerWeight", 1f);
 }
Beispiel #13
0
 public void SetLocomotionState(LocomotionState state)
 {
     updateUserVars(new Dictionary <SocketUserVars, object> {
         {
             SocketUserVars.LOCOMOTION_STATE,
             (state == LocomotionState.Default) ? null : new byte?((byte)state)
         }
     });
 }
Beispiel #14
0
            public void UpdateGraphLogic(float deltaTime)
            {
                var animState   = m_AnimStateData.charLocoState;
                var firstUpdate = animState != m_LastAnimState;

                m_LastAnimState = animState;

                if (m_AnimStates[(int)animState].animStateUpdater != null)
                {
                    m_AnimStates[(int)animState].animStateUpdater.UpdatePresentationState(firstUpdate, deltaTime);
                }
            }
Beispiel #15
0
        private void locomotionStateChanged(LocomotionState state)
        {
            switch (state)
            {
            case LocomotionState.Slide:
                if (receivingEnabled)
                {
                    locomotionTracker.SetCurrentController <SlideController>();
                    break;
                }
                pendingSlide = true;
                pendingRun   = false;
                break;

            case LocomotionState.Racing:
                if (receivingEnabled)
                {
                    if (playerDataHandle.IsLocalPlayer)
                    {
                        locomotionTracker.SetCurrentController <RaceController>();
                    }
                    else if (LocomotionHelper.IsCurrentControllerOfType <SlideController>(base.gameObject))
                    {
                        locomotionTracker.SetCurrentController <RaceController>();
                    }
                    else
                    {
                        locomotionTracker.SetCurrentController <SlideController>();
                    }
                }
                else
                {
                    pendingSlide = true;
                    pendingRun   = false;
                }
                break;

            case LocomotionState.Default:
                if (receivingEnabled)
                {
                    locomotionTracker.SetCurrentController <RunController>();
                    break;
                }
                pendingSlide = false;
                pendingRun   = true;
                break;

            default:
                pendingSlide = false;
                pendingRun   = false;
                break;
            }
        }
Beispiel #16
0
 private void FlyUp()
 {
     if (HelperFunctions.IsWithinRange(FLYING_HEIGHT - ON_TILE_THRESHOLD,
                                       FLYING_HEIGHT + ON_TILE_THRESHOLD, transform.position.y))
     {
         _locomotionState = LocomotionState.Flying;
     }
     else
     {
         MoveYPositionUp();
     }
 }
Beispiel #17
0
 public State()
 {
     this.forwardSpeed    = Vector3.zero;
     this.sidesSpeed      = 0f;
     this.targetLock      = false;
     this.isGrounded      = 1.0f;
     this.isSliding       = 0.0f;
     this.isDashing       = 0.0f;
     this.verticalSpeed   = 0f;
     this.normal          = Vector3.zero;
     this.locomotionState = LocomotionState.Grounded;
 }
    //takes user input, converts to scale and applies to biped model
    void ProportionalStrideInput()
    {
        proportionalStrideLength = Mathf.InverseLerp(0.0f, userInput.maxVelocity, userInput.velocity);

        if (proportionalStrideLength > 0.31f)
        {
            locomotionState = LocomotionState.Walking;
        }
        else
        {
            locomotionState          = LocomotionState.StandingStill;
            proportionalStrideLength = 0.3f;
        }
    }
Beispiel #19
0
    public void RunAwayFlyUp()
    {
        OrientInDirection();

        if (HelperFunctions.IsWithinRange(FLYING_HEIGHT - ON_TILE_THRESHOLD,
                                          FLYING_HEIGHT + ON_TILE_THRESHOLD, transform.position.y))
        {
            _locomotionState = LocomotionState.RunAwayOut;
        }
        else
        {
            MoveYPositionUp();
        }
    }
 void UpdateState(Entity entity, LocomotionState locoData, LocomotionStateStack stack)
 {
     LocomotionState.State locoState = locoData.LocoState;
     if (locoData.StateEndType == LocomotionState.EndType.None)
     {
         return;
     }
     // Debug.Log("be end type : "+locoData.StateEndType+" locoData.EndTime:"+locoData.EndTime);
     if (locoData.StateEndType == LocomotionState.EndType.PlayAnimationOnce)
     {
         if (locoData.EndTime == 0)
         {
             //最少要播放动画一帧
             locoData.EndTime = 1;
             EntityManager.SetComponentData <LocomotionState>(entity, locoData);
             return;
         }
         var hasLooks = EntityManager.HasComponent <LooksInfo>(entity);
         if (!hasLooks)
         {
             Debug.LogError("has no looks! uid : " + EntityManager.GetComponentData <UID>(entity).Value);
             return;
         }
         var looksInfo = EntityManager.GetComponentData <LooksInfo>(entity);
         if (looksInfo.CurState != LooksInfo.State.Loaded)
         {
             return;
         }
         var      looksEntity = looksInfo.LooksEntity;
         Animator animator    = EntityManager.GetComponentObject <Animator>(looksEntity);
         if (animator == null)
         {
             return;
         }
         // Debug.Log("animator.GetCurrentAnimatorStateInfo(0).normalizedTime : "+animator.GetCurrentAnimatorStateInfo(0).normalizedTime);
         if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f)
         {
             BackToLastState(entity, stack);
         }
     }
     else if (locoData.StateEndType == LocomotionState.EndType.EndTime)
     {
         // Debug.Log("locoData.EndTime >= TimeEx.ServerTime : "+(TimeEx.ServerTime >= locoData.EndTime)+" "+locoData.EndTime+" "+TimeEx.ServerTime);
         if (TimeEx.ServerTime >= locoData.EndTime)
         {
             BackToLastState(entity, stack);
         }
     }
 }
    public void ConnectIfNeeded(DataEntityHandle handle, LocomotionState state)
    {
        if (dataEntityCollection.TryGetComponent(dataEntityCollection.LocalPlayerHandle, out GameObjectReferenceData component) && isInteractingWithZiplineActionGraph(component.GameObject))
        {
            return;
        }
        LocomotionData component2 = dataEntityCollection.GetComponent <LocomotionData>(handle);

        if (!component2.LocomotionStateIsInitialized && state == LocomotionState.Zipline && dataEntityCollection.TryGetComponent(handle, out component))
        {
            GameObject gameObject = component.GameObject;
            if (gameObject != null && !gameObject.IsDestroyed())
            {
                connectPlayerObject(gameObject);
            }
        }
    }
Beispiel #22
0
 void UpdateAnimator(Animator animator, LocomotionState locoData)
 {
     LocomotionState.State locoState = locoData.LocoState;
     // Debug.Log("locoState : "+locoState);
     if (locoState == LocomotionState.State.Idle && !animator.GetCurrentAnimatorStateInfo(0).IsName("idle"))
     {
         // animator.CrossFade("idle", 0.2f, 0, Time.deltaTime);
         animator.Play("idle");
     }
     else if (locoState == LocomotionState.State.Run && !animator.GetCurrentAnimatorStateInfo(0).IsName("run"))
     {
         // animator.CrossFade("run", 0.2f, 0, Time.deltaTime);
         animator.Play("run");
     }
     else if (locoState == LocomotionState.State.BeHit && !animator.GetCurrentAnimatorStateInfo(0).IsName("behit"))
     {
         animator.Play("behit");
     }
     else if (locoState == LocomotionState.State.Jump && !animator.GetCurrentAnimatorStateInfo(0).IsName("jump"))
     {
         animator.Play("jump");
     }
     else if (locoState == LocomotionState.State.DoubleJump && !animator.GetCurrentAnimatorStateInfo(0).IsName("jump2"))
     {
         animator.Play("jump2");
     }
     else if (locoState == LocomotionState.State.TrebleJump && !animator.GetCurrentAnimatorStateInfo(0).IsName("jump3"))
     {
         animator.Play("jump3");
     }
     else if (locoState == LocomotionState.State.Dead && !animator.GetCurrentAnimatorStateInfo(0).IsName("death"))
     {
         // Debug.Log("TimeEx.ServerTime:"+TimeEx.ServerTime+" startTime:"+locoData.StartTime+" "+((Time.time - locoData.StartTime)));
         // if (Time.time - locoData.StartTime <= 1)
         // {
         animator.Play("death");
         // }
         // else
         // {
         //     //have been dead for a long time
         //     animator.Play("death", 0, 1.0f);
         // }
     }
 }
Beispiel #23
0
    // Attempt to escape the map
    protected override void HandleEscaping()
    {
        switch (_locomotionState)
        {
        case LocomotionState.RunAwayUp:
            RunAwayFlyUp();
            break;

        case LocomotionState.RunAwayOut:
            MoveToNextTile();
            break;

        default:
            // If somehow got here from any other state, prepare to
            // run away
            _locomotionState = LocomotionState.RunAwayUp;
            break;
        }
    }
Beispiel #24
0
    // Handle how this enemy should behave once it has reached its target
    protected override void HandleOnTarget()
    {
        switch (_locomotionState)
        {
        case LocomotionState.Flying:
            Debug.Log("EnemyCrow.HandleOnTarget(): Switch to Eating state");
            actionTimer.StartTimer();
            _locomotionState = LocomotionState.Hovering;
            break;

        case LocomotionState.Hovering:
            Hover();
            break;

        case LocomotionState.FlyingDown:
            FlyDown();
            break;
        }
    }
Beispiel #25
0
    private void FlyDown()
    {
        if (transform.position.y <= 0)
        {
            _locomotionState = LocomotionState.Eating;
            currentState     = EnemyState.Eating;
            actionTimer.StartTimer();

            // Add this crow to the list of enemies on the tile
            //gameController.TileMap.AddEnemyToTile( currentTilePos, this );
        }
        else
        {
            Vector3 vectorDown = new Vector3(transform.position.x, 0,
                                             transform.position.z);

            // Fly down
            float displacementPerTime = FLYING_Y_SPEED * Time.deltaTime;
            transform.position = Vector3.MoveTowards(transform.position,
                                                     vectorDown, displacementPerTime);
        }
    }
Beispiel #26
0
 private void CalculateCanJump(bool TryingToJump)
 {
     if (TryingToJump == false) //released/up
     {
         if (_canJump == false)
         {
             _canJump = true;
             OnCanJump?.Invoke(true);
         }
     }
     else
     {
         if (_canJump == true)
         {
             OnGroundContactLost();
             _state = LocomotionState.Jumping;
             OnStateChange?.Invoke(_state);
             currentJumpStartTime = Time.time;
             Jump(_jumpHeight);
         }
     }
 }
Beispiel #27
0
    private void Hover()
    {
        _angle += ROTATION_ANGLE_UPDATE * Time.deltaTime;
        if (_angle >= 360)
        {
            _angle = 0;
        }

        // Rotate around target coordinates
        float xPrime = (ROTATION_RADIUS * ( float )Math.Cos(_angle)) +
                       (targetFinalPos.CoordX + TILE_CENTER_OFFSET);
        float zPrime = (ROTATION_RADIUS * ( float )Math.Sin(_angle)) +
                       (targetFinalPos.CoordZ + TILE_CENTER_OFFSET);

        transform.position = new Vector3(xPrime, transform.position.y, zPrime);

        if (actionTimer.GetTicks() >= HOVER_TIME_IN_SECONDS)
        {
            actionTimer.StopTimer();
            _locomotionState = LocomotionState.FlyingDown;
        }
    }
    private void OnLocomotionStateChanged(LocomotionState state)
    {
        switch (state)
        {
        case LocomotionState.Slide:
            break;

        case LocomotionState.Default:
            base.Fsm.Event(InteractEvent);
            break;

        case LocomotionState.GenericState1:
            base.Fsm.Event(Action1Event);
            break;

        case LocomotionState.GenericState2:
            base.Fsm.Event(Action2Event);
            break;

        case LocomotionState.GenericState3:
            base.Fsm.Event(Action3Event);
            break;
        }
    }
        /// <summary>
        /// Sets the locomotion new locomotion state and
        /// associated layer.
        /// </summary>
        /// <param name="state">State.</param>
        private void SetLocomotionState( LocomotionState state )
        {
            _locoState = state;

            switch ( _locoState )
            {
            case LocomotionState.Falling:
                gameObject.layer = LayerMask.NameToLayer( "fall" );
                break;
            case LocomotionState.Jumping:
                gameObject.layer = LayerMask.NameToLayer( "jump" );
                _hasReachedJumpVelocity = false;
                break;
            case LocomotionState.Walking:
            default:
                break;
            }
        }
    void FixedUpdate( )
    {
        if ( !m_RobotComponent.bCanMove || !GameManager.Instance.m_MatchStarted )
        {
            m_NavAgent.Stop( );
            return;
        }
        else
        {
            m_NavAgent.Resume( );
        }

        if ( m_NavAgent.velocity != Vector3.zero ) m_CurrentLocomotionState = LocomotionState.MOVING;
        else m_CurrentLocomotionState = LocomotionState.IDLE;

        //Handle moving
        switch ( m_CurrentLocomotionState )
        {
            case LocomotionState.IDLE:

                Vector3 _targetLoc = GetRandomLocationNearPlayer();
                if ( _targetLoc != Vector3.zero )
                {
                    m_NavAgent.SetDestination( _targetLoc );
                    return;
                }

                if ( Vector3.Distance( transform.position, _targetLagLocation ) < 6 )
                {
                    transform.LookAt( _targetLagLocation, Vector3.up );
                }

                break;

            case LocomotionState.MOVING:
                _targetLagLocation = Vector3.Lerp( _targetLagLocation, m_PlayerCurrentLocation, 0.03f );
                transform.LookAt( _targetLagLocation, Vector3.up );

                if ( Vector3.Distance( transform.position, _targetLagLocation ) < 3 )
                {
                    m_NavAgent.Stop( );
                }
                else
                {
                    m_CurrentLocomotionState = LocomotionState.IDLE;
                }
                break;
        }

        //Handle firing
        switch ( m_CurrentFireState )
        {
		case FireState.AIMING:

			if (Vector3.Distance (m_PlayerCurrentLocation, transform.position) < 3) {
				if (!m_IsFiringLeftWeapon) {
					FireLeftWeapon ();
				}

				if (!m_IsFiringRightWeapon) {
					FireRightWeapon ();
				}
			} else
				m_CurrentFireState = FireState.AIMING;
                break;

            case FireState.FIRING:

                break;
        }
    }
 public virtual void SetState(LocomotionState state)
 {
 }
Beispiel #32
0
 public PlayerLocoStateChanged(long sessionId, LocomotionState state)
 {
     SessionId = sessionId;
     State     = state;
 }