예제 #1
0
    /** 寻路移动到(主动) */
    public void moveTo(int unitMoveType, PosData pos, float dis)
    {
        if (!canMoveNow())
        {
            return;
        }

        if (dis < 0f)
        {
            return;
        }

        //位置纠正
        BaseGameUtils.makeTerrainPos(pos);

        //相同点
        if (_d.baseMoveState == UnitBaseMoveState.MoveToPos && _moveTargetPos.isEquals(pos))
        {
            return;
        }

        _isMoveToUnit = false;
        _moveTargetUnit.clear();
        toMoveToList(unitMoveType, pos, MathUtils.floatEquals(dis, 0f) ? 0f:dis *dis);
    }
예제 #2
0
    /** 服务器移动点组 */
    public void onServerMovePosList(int type, SList <PosData> list, int moveTime)
    {
        PosData[] values = list.getValues();

        for (int i = 0, len = list.size(); i < len; ++i)
        {
            BaseGameUtils.makeTerrainPos(values[i]);
        }

        clearMoveList();

        _moveList.addAll(list);

        if (CommonSetting.needMoveLerp)
        {
            setServerMoveRatio(list.get(0), moveTime);
        }

        clearBaseMove();

        _d.baseMoveState         = UnitBaseMoveState.MoveToPos;
        _d.moveType              = type;
        _currentMoveIsInitiative = false;
        _moveListIndex           = 0;

        doMoveList();
    }
예제 #3
0
    /** 服务器移动点 */
    public void onServerMovePos(int type, PosData pos, int moveTime)
    {
        BaseGameUtils.makeTerrainPos(pos);
        clearMoveList();

        if (CommonSetting.needMoveLerp)
        {
            setServerMoveRatio(pos, moveTime);
        }

        baseMoveToPos(type, pos, false);
    }
예제 #4
0
    public override void findRayPos(int moveType, PosData re, PosData from, float direction, float length)
    {
        re.y = from.y;
        polar2D(re, length, direction);
        addPos2D(re, from);
        clampPos(re);


        BaseGameUtils.makeTerrainPos(re);
        if (NavMesh.Raycast(from.getVector(), re.getVector(), out NavMeshHit hit, BaseC.constlist.mapMoveType_getMask(moveType)))
        {
            //赋值为碰撞点
            re.setByVector(hit.position);
        }
    }
예제 #5
0
    /** 服务器特殊移动 */
    public void onServerSpecialMove(PosDirData posDir, int id, int[] args, int lastTime, PosData baseMovePos)
    {
        if (_scene.driveType != SceneDriveType.ServerDriveDamage)
        {
            BaseGameUtils.makeTerrainPos(posDir.pos);
            BaseGameUtils.makeTerrainPos(baseMovePos);

            _unit.pos.setByPosDir(posDir);
        }

        clearBaseMove();

        _d.specialMoveLastTime = lastTime;
        _d.baseMovePos         = baseMovePos;

        //视为非新执行
        toSpecialMove(id, args, false, false);
    }
예제 #6
0
    protected void driveMoveFrame(float delay)
    {
        DriveLogic drive = _drive;

        _tempPos.clear();

        DriveData dData = _d.driveData;

        float speedAbs = Math.Abs(drive.driveCurrentMoveSpeedM);

        if (speedAbs == 0 && dData.forward == 0)
        {
            if (dData.turn == 0 || !drive.canDriveTurnAtPivot)
            {
                return;
            }
        }

        //本次移动距离
        float dis;

        //不启用加速度
        if (drive.driveAccelerateSpeedM == 0)
        {
            dis = _useMoveSpeedM * delay * dData.forward;
        }
        else
        {
            //滑行
            if (dData.forward == 0)
            {
                //需要的减速时间
                float nTime = speedAbs / drive.driveGroundFrictionM;
                float useA  = drive.driveCurrentMoveSpeedM > 0 ? -drive.driveGroundFrictionM : drive.driveGroundFrictionM;

                if (delay <= nTime)
                {
                    float d = useA * delay;
                    dis = drive.driveCurrentMoveSpeedM * delay + d * delay / 2;
                    drive.driveCurrentMoveSpeedM += d;
                }
                //减到0
                else
                {
                    dis = drive.driveCurrentMoveSpeedM * nTime / 2;              //vt/2
                    drive.driveCurrentMoveSpeedM = 0;
                }
            }
            else
            {
                float useA       = drive.driveAccelerateSpeedM * dData.forward;
                bool  sameSymbol = MathUtils.sameSymbol(useA, drive.driveCurrentMoveSpeedM);

                //符号相同,并且已经是最高速度
                if (sameSymbol && speedAbs >= _useMoveSpeedM)
                {
                    dis = drive.driveCurrentMoveSpeedM * delay;
                }
                else
                {
                    //需要加速的时间
                    float nTime = (_useMoveSpeedM - (sameSymbol ? speedAbs : -speedAbs)) / drive.driveAccelerateSpeedM;

                    //匀加速
                    if (delay <= nTime)
                    {
                        float d = useA * delay;
                        dis = drive.driveCurrentMoveSpeedM * delay + d * delay / 2;
                        drive.driveCurrentMoveSpeedM += d;
                    }
                    //到max
                    else
                    {
                        dis = drive.driveCurrentMoveSpeedM * nTime + useA * nTime * nTime / 2;

                        //到达最大速度
                        drive.driveCurrentMoveSpeedM = useA > 0 ? _useMoveSpeedM : -_useMoveSpeedM;
                        //剩余时间用新速度
                        dis += (drive.driveCurrentMoveSpeedM * (delay - nTime));
                    }
                }
            }
        }

        bool hasPos = false;
        bool hasDir = false;

        if (dData.turn == 0)
        {
            if (dis != 0)
            {
                _scenePosLogic.calculateVectorByDir(_tempPos, _dir, dis);
                _scenePosLogic.addPos(_tempPos, _pos);
                hasPos = true;
            }
            else
            {
                return;
            }
        }
        else
        {
            if (dis != 0)
            {
                float angle;
                float radius;

                if (drive.canDriveTurnAtPivot)
                {
                    angle  = drive.driveDirectionSpeed * delay;
                    radius = dis / angle;
                }
                else
                {
                    radius = drive.driveTurnRadius;
                    angle  = dis / radius;
                }

                //正方向
                float forward = (float)(radius * Math.Sin(angle));
                //两侧
                float side = (float)(radius * (1 - Math.Cos(angle)));

                _tempPos.x = forward;
                _tempPos.z = dData.turn * side;
                _tempPos.y = 0;

                //朝向向量
                _scenePosLogic.rotatePosByDir2D(_tempPos, _dir);
                _scenePosLogic.addPos(_tempPos, _pos);

                //朝向修改
                _dir.direction = MathUtils.directionCut(_dir.direction - (angle * dData.turn));
                hasDir         = true;
                hasPos         = true;
            }
            else
            {
                if (drive.canDriveTurnAtPivot)
                {
                    float angle = drive.driveDirectionSpeed * delay;
                    _dir.direction = MathUtils.directionCut(_dir.direction - (angle * dData.turn));
                    hasDir         = true;
                }
                else
                {
                    return;
                }
            }
        }

        BaseGameUtils.makeTerrainPos(_tempPos);

        if (hasDir)
        {
            _unit.pos.onSetDir();
        }

        if (hasPos)
        {
            if (_scenePosLogic.isPosEnabled(_moveType, _tempPos))
            {
                _pos.copyPos(_tempPos);
                _unit.pos.onSetPos();
            }
            else
            {
                // Ctrl.print("撞墙",_tempPos.toDataString());
            }
        }


        if (drive.driveAccelerateSpeedM != 0 && drive.driveCurrentMoveSpeedM == 0f && dData.forward == 0 && _currentMoveIsInitiative)
        {
            if (!drive.canDriveTurnAtPivot || dData.turn == 0)
            {
                stopMove();
            }
        }
    }