コード例 #1
0
        public bool OnMove(EntityMovement entity_movement, float dt)
        {
            Vector3 move_to_pos = Vector3.MoveTowards(entity_movement.trans.position, target, speed * Time.deltaTime);

            entity_movement.trans.position = move_to_pos;


            var distance = (entity_movement.trans.position - target).magnitude;

            if (distance <= 0.01f)
            {
                EntityEventFactory.ChangeInEntityState(entity_movement._base_entity, E_StateId.idle);
                return(true);
            }
            return(false);
        }
コード例 #2
0
        // 初始化GameObject的相关东西
        private void _init_gameobject()
        {
            // 加载模型
            BaseEntityController go = TransformPool.Instance.Pop <BaseEntityController>
                                          ("res_bundle/prefab/model/Character/" + "NPC_Zhaoyun_001_02.prefab" /*_cnf.prefab_name*/);

            EntityController = go;
            EntityController.InitOutTrigger(this, this, this);

            _animGroup = go.GetAnimationGroup();
            _animGroup.OnInit(this);
            _animGroup.OnRegisterHandler();

            _movement = go.GetComponent <EntityMovement>();
            _movement._base_entity = this;
        }
コード例 #3
0
        public Vector3 move_direction = Vector3.zero;                       // 键盘目标方向
        public bool OnMove(EntityMovement entity_movement, float dt)
        {
            if (entity_movement._base_entity.GetState() != E_StateId.move)
            {
                return(true);
            }

            // 1.是否到达目的地
            //if (!_reach_target_pos) return;
            if (move_direction == Vector3.zero)
            {
                EntityEventFactory.ChangeInEntityState(entity_movement._base_entity, E_StateId.idle);
                return(true);
            }
            Vector3 cur_position = entity_movement.trans.position;
            //cur_position = NavMeshHelper.MakeReasonablePos(cur_position);

            //float target_height = NavMeshHelper.GetGroundHeightY(cur_position + NAVMESH_RADIUS * move_direction);
            //if (MathHelper.IsEqual(target_height, MovementConst.error_height))
            //    return;

            // 2.移动的距离
            Vector3 distance = move_direction * dt * entity_movement.movespeed;
            //Vector3 normal = trans.forward.normalized * distance.magnitude;

            //Vector3 tp = Quaternion.Euler(move_direction)*distance;
            // 3.下一个位置
            Vector3 next_pos = cur_position + distance;

            /* float height = NavMeshHelper.GetGroundHeightY(next_pos);
             * if (!MathHelper.IsEqual(height, MovementConst.error_height))
             *   next_pos.y = height;*/

            next_pos = NavMeshHelper.MakeReasonablePos(next_pos);
            entity_movement.trans.position = next_pos;
            // _update_direction();
            entity_movement.OnRotating(move_direction);
            move_direction = Vector3.zero;

            /*if (!NavMesh.CalculatePath(cur_position, next_pos, NavMesh.AllAreas, nav_path))
             * {
             *  return;
             * }
             * if (nav_path.corners.Length < 2)
             * {
             *  if (nav_path.corners.Length == 1)   //有时会寻路出一个点的情况,这个还没好好研究
             *  {
             *      distance = nav_path.corners[0] - cur_position;
             *      distance = distance.normalized * dt * 5;
             *      next_pos = cur_position + distance;
             *      trans.position = next_pos;
             *  }
             *  else
             *  {
             *      //m_movement = Vector3.zero;
             *
             *  }
             * }
             * else
             * {
             *  distance = nav_path.corners[1] - cur_position;  //调整方向
             *  distance = distance.normalized * dt * 5;
             *
             *  next_pos = cur_position + distance;
             *
             *  trans.position = next_pos;
             * }*/
            return(false);
        }