protected override int onExecute(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData   = wData.As <AIEntityWorkingData>();
            Vector3             targetPos  = TMathUtils.Vector3ZeroY(thisData.entity.GetBBValue <Vector3>(AIEntity.BBKEY_NEXTMOVINGPOSITION, Vector3.zero));
            Vector3             currentPos = TMathUtils.Vector3ZeroY(thisData.entityTF.position);

            if (TMathUtils.IsZero((targetPos - currentPos).sqrMagnitude))
            {
                return(TBTRunningStatus.FINISHED);
            }
            else
            {
                Vector3 toTarget   = TMathUtils.GetDirection2D(targetPos, currentPos);
                Vector3 curFacing  = thisData.entityTF.forward;
                float   dotV       = Vector3.Dot(toTarget, curFacing);
                float   deltaAngle = Mathf.Acos(Mathf.Clamp(dotV, -1f, 1f));
                if (deltaAngle < 0.1f)
                {
                    thisData.entityTF.forward = toTarget;
                    return(TBTRunningStatus.FINISHED);
                }
                else
                {
                    Vector3 crossV      = Vector3.Cross(curFacing, toTarget);
                    float   angleToTurn = Mathf.Min(3f * thisData.deltaTime, deltaAngle);
                    if (crossV.y < 0)
                    {
                        angleToTurn = -angleToTurn;
                    }
                    thisData.entityTF.Rotate(Vector3.up, angleToTurn * Mathf.Rad2Deg, Space.World);
                }
            }
            return(TBTRunningStatus.EXECUTING);
        }
        protected override int onExecute(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData   = wData.As <AIEntityWorkingData>();
            Vector3             targetPos  = TMathUtils.Vector3ZeroY(thisData.entity.GetBBValue <Vector3>(AIEntity.BBKEY_NEXTMOVINGPOSITION, Vector3.zero));
            Vector3             currentPos = TMathUtils.Vector3ZeroY(thisData.entityTF.position);
            float distToTarget             = TMathUtils.GetDistance2D(targetPos, currentPos);

            if (distToTarget < 1f)
            {
                thisData.entityTF.position = targetPos;
                return(TBTRunningStatus.FINISHED);
            }
            else
            {
                int     ret        = TBTRunningStatus.EXECUTING;
                Vector3 toTarget   = TMathUtils.GetDirection2D(targetPos, currentPos);
                float   movingStep = 0.5f * thisData.deltaTime;
                if (movingStep > distToTarget)
                {
                    movingStep = distToTarget;
                    ret        = TBTRunningStatus.FINISHED;
                }
                thisData.entityTF.position = thisData.entityTF.position + toTarget * movingStep;
                return(ret);
            }
        }
        public override bool IsTrue(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData   = wData.As <AIEntityWorkingData>();
            Vector3             targetPos  = TMathUtils.Vector3ZeroY(thisData.entity.GetBBValue <Vector3>(AIEntity.BBKEY_NEXTMOVINGPOSITION, Vector3.zero));
            Vector3             currentPos = TMathUtils.Vector3ZeroY(thisData.entityTF.position);

            return(TMathUtils.GetDistance2D(targetPos, currentPos) < 1f);
        }
Example #4
0
        public override bool IsTrue(BtWorkingData workData)
        {
            AIEntityWorkingData this_data   = workData.As <AIEntityWorkingData>();
            Vector3             target_pos  = MathHelper.Vector3ZeroY(this_data.EntityAi.GetBbValue <Vector3>(BtEntityAi.BBKEY_NEXTMOVINGPOSITION, Vector3.zero));
            Vector3             current_pos = MathHelper.Vector3ZeroY(this_data.EntityAi.BaseEntity.EntityController.WroldPosition);
            bool result = TMathUtils.GetDistance2D(target_pos, current_pos) < 1f;

            return(result);
        }
Example #5
0
        public int UpdateReqeust(float gameTime, float deltaTime)
        {
            if (_nextRequest != _currentRequest)
            {
                //reset bev tree
                _behaviorTree.Transition(_behaviorWorkingData);
                //assign to current
                _currentRequest = _nextRequest;

                //reposition and add a little offset
                Vector3 targetPos = _currentRequest.nextMovingTarget + TMathUtils.GetDirection2D(_currentRequest.nextMovingTarget, transform.position) * 0.2f;
                Vector3 startPos  = new Vector3(targetPos.x, -1.4f, targetPos.z);
                _targetDummyObject.transform.position = startPos;
                LeanTween.move(_targetDummyObject, targetPos, 1f);
            }
            return(0);
        }