Example #1
0
 /// <summary>
 /// Execute the movement of the current motion state
 /// </summary>
 public void Execute(ACharacterSystem cs, MotionInformation mi)
 {
     if (_currentMotionState != null)
     {
         _currentMotionState.Move(cs, mi, _motionType);
     }
 }
Example #2
0
        protected override void Move3D(ACharacterSystem3D cs, MotionInformation mi)
        {
            var correctAmountOfAngularSpeed = cs.LocomotionProfile.LerpAngularSpeed(Mathf.Abs(mi.Input.MovementDirection.z));

            if (mi.Configuration.ShouldAdaptToNavMesh)
            {
                mi.Input.MovementDirection = cs.transform.InverseTransformDirection(mi.Input.MovementDirection);
            }
            cs.transform.Rotate(0f, mi.Input.MovementDirection.x * correctAmountOfAngularSpeed * Time.fixedDeltaTime, 0f, Space.Self);
            cs.transform.Translate(0f, 0f, mi.Input.MovementDirection.z * cs.LocomotionProfile.WalkSpeed * Time.fixedDeltaTime, Space.Self);
        }
Example #3
0
        ////////////////////////////
        ////////// Method //////////
        ////////////////////////////

        /////////////////////////
        ////////// API //////////

        /// <summary>
        /// Attempt to get the next motion state base on the motion transition of the current motion state
        /// </summary>
        public AMotionState AttemptToGetNextMotionState(ACharacterSystem cs, MotionInformation mi, EMotionType motionType)
        {
            foreach (var mt in _motionTransitions)
            {
                var nextMotionState = mt.GetResultingMotionState(cs, mi, motionType);
                if (nextMotionState != null)
                {
                    return(nextMotionState);
                }
            }
            return(null);
        }
        ////////////////////////////
        ////////// Method //////////
        ////////////////////////////

        /////////////////////////
        ////////// API //////////

        /// <summary>
        /// Verify if the condition is complete
        /// </summary>
        public bool IsComplete(ACharacterSystem cs, MotionInformation mi, EMotionType motionType)
        {
            switch (motionType)
            {
            case EMotionType.Motion2D:
                return(IsComplete2D(cs as ACharacterSystem2D, mi));

            case EMotionType.Motion3D:
                return(IsComplete3D(cs as ACharacterSystem3D, mi));

            default:
                throw new ArgumentOutOfRangeException("motionType", motionType, null);
            }
        }
Example #5
0
        /// <summary>
        /// Execute the movemement of the motion state
        /// </summary>
        public void Move(ACharacterSystem cs, MotionInformation mi, EMotionType motionType)
        {
            switch (motionType)
            {
            case EMotionType.Motion2D:
                Move2D(cs as ACharacterSystem2D, mi);
                break;

            case EMotionType.Motion3D:
                Move3D(cs as ACharacterSystem3D, mi);
                break;

            default:
                throw new ArgumentOutOfRangeException("motionType", motionType, null);
            }
        }
Example #6
0
        /// <summary>
        /// Update the current motion state
        /// </summary>
        public void Update(ACharacterSystem cs, MotionInformation mi)
        {
            if (_currentMotionState == null)
            {
                return;
            }

            var nextMotionState = _currentMotionState.AttemptToGetNextMotionState(cs, mi, _motionType);

            if (nextMotionState != null)
            {
                _previousMotionState = _currentMotionState;
                _currentMotionState  = nextMotionState;
                if (ShouldDisplayDebugTransitionLog)
                {
                    DisplayDebugTransitionLog();
                }
            }
        }
Example #7
0
 protected override void Move3D(ACharacterSystem3D cs, MotionInformation mi)
 {
 }
 /// <summary>
 /// Callback to verify if the condition is complete for the 3D space
 /// </summary>
 protected abstract bool IsComplete3D(ACharacterSystem3D cs, MotionInformation mi);
Example #9
0
 /// <summary>
 /// Callback to execute the movemement of the motion state in 3D space
 /// </summary>
 protected abstract void Move3D(ACharacterSystem3D cs, MotionInformation mi);
 protected override bool IsComplete3D(ACharacterSystem3D cs, MotionInformation mi)
 {
     return(mi.Input.MovementDirection.x != 0f || mi.Input.MovementDirection.y != 0f || mi.Input.MovementDirection.z != 0f);
 }
Example #11
0
        /////////////////////////////
        ////////// Service //////////

        /// <summary>
        /// Check if all the conditions are met
        /// </summary>
        private bool AreConditionsMet(ACharacterSystem cs, MotionInformation mi, EMotionType motionType)
        {
            return(_motionConditions.All(mc => mc.IsComplete(cs, mi, motionType)));
        }
Example #12
0
        ////////////////////////////
        ////////// Method //////////
        ////////////////////////////

        /////////////////////////
        ////////// API //////////

        /// <summary>
        /// Return either the motionStateOnSuccess or the motionStateOnFailure depending on the conditions result
        /// </summary>
        public AMotionState GetResultingMotionState(ACharacterSystem cs, MotionInformation mi, EMotionType motionType)
        {
            return(AreConditionsMet(cs, mi, motionType) ? _motionStateOnSuccess : _motionStateOnFailure);
        }
 protected override bool IsComplete2D(ACharacterSystem2D cs, MotionInformation mi)
 {
     return(mi.Input.MovementDirection.x == 0f && mi.Input.MovementDirection.y == 0f && mi.Input.MovementDirection.z == 0f);
 }