채팅0

    lua고수님덜 도와주십쇼

    조회수 430
    1. 테이블에서 거리로 거르고

    2. 젤가까운놈 선택해서

    3. 쳐다보게한다음

    4. 알아서 때리게 하고싶은데

    쳐다보게 하고 때리는거까진 했는데 테이블초기화가 문제인지 그다음 테이블 탐색을 안하고 계속 같은방향만 때리네요..


    13번째 테스트에서 막혔습니다 ㅜ 어디가 문제인지 모르겠어요


    아래는 스크립트 입니다.. 초기화부분 회색표시했어요


    [살아있는 몹 걸러서]


    local function calculateDistance(pos1, pos2) -- 거리 계산함수

    local dx = pos1.x - pos2.x

    local dy = pos1.y - pos2.y

    local dz = pos1.z - pos2.z

    return math.sqrt(dxdx + dydy + dz*dz)

    end


    local function calculateXDistance(pos1, pos2) -- x축 거리 계산 함수

    return pos1.x - pos2.x

    end


    local function calculateYDistance(pos1, pos2)-- y축 거리 계산 함수

    return pos1.y - pos2.y

    end


    [박스로 충돌감지]

    if not lookableMobs then -- 기존 lookableMobs 테이블을 사용하거나 초기화

    lookableMobs = {}

    else


    lookableMobs = {} -- 이전에 추가된 몬스터가 사라지면 테이블 초기화

    end

    for _, mob in ipairs(output) do
        local mob_pos = mob.Entity.TransformComponent.WorldPosition
        local xDistance = calculateXDistance(player_pos, mob_pos)
        local yDistance = calculateYDistance(player_pos, mob_pos)
    
        -- 거리에 따른 조건 추가
        if xDistance >= 4 or yDistance >= 1 then
            goto continue
        end
    
        local dist = calculateDistance(player_pos, mob_pos)
        table.insert(distanceTable, {mob = mob, distance = dist})
    
        ::continue::
    end
    
    -- 거리에 따라 테이블 정렬
    table.sort(distanceTable, function(a, b) return a.distance < b.distance end)
    
    for _, mobInfo in ipairs(distanceTable) do
        table.insert(lookableMobs, mobInfo.mob)
        break -- 첫 번째 몬스터만 추가하고 반복문 종료
    end

    if #lookableMobs > 0 then

    -- 가장 가까운 몬스터가 있는 경우

    -- 첫 번째 몬스터의 위치
    local mob_pos = lookableMobs[1].Entity.TransformComponent.WorldPosition
    
    -- 몬스터를 바라보도록 캐릭터의 방향 설정
    local lookDirectionX = 1  -- 오른쪽을 바라보도록 초기값 설정
    if player_pos.x > mob_pos.x then
        lookDirectionX = -1  -- 몬스터가 왼쪽에 있으면 왼쪽을 바라보도록 설정
    end
    _UserService.LocalPlayer.PlayerControllerComponent.LookDirectionX = lookDirectionX
    
    -- 특정 몬스터를 바라봤다는 상태 변수 설정
    zz_y7.looked_to_mob = true
    
    -- 캐릭터의 이동을 가능하게 설정
    _UserService.LocalPlayer.WsUser:SetMovementEnable(true)

    else

    -- 가장 가까운 몬스터가 없는 경우

    -- 일정 방향을 계속 바라보도록 설정 (예: 오른쪽)
    local defaultLookDirectionX = 1  -- 오른쪽을 바라보도록 설정
    _UserService.LocalPlayer.PlayerControllerComponent.LookDirectionX = defaultLookDirectionX
    
    -- 특정 몬스터를 바라보지 않았다는 상태 변수 설정
    zz_y7.looked_to_mob = false
    
    -- 캐릭터의 이동을 가능하게 설정
    _UserService.LocalPlayer.WsUser:SetMovementEnable(true)

    end

    end


    zz_y7.hit_timer_func = function(self)

    if zz_y7.looked_to_mob then

    [픽업]

    [스킬사용]

    [자동물약]

    end

    댓글4

    회원프로필

    이거 근데 유저 움직이는건 어케 구현햇음?
    순간이동말고 걷는것도 거능함? 아무리해도 안옴직여서 ㅜ

    2024.01.26 02:34
    회원프로필

    님 예전에 사람인식 텔포 찾지 않으셨나요? 저 그거 귀찮게 하는법 아는데 알려드릴까요?

    2024.01.26 02:42
    회원프로필

    앗 그건 해결햇어여
    케릭터 걸어서 움직이게 하고싶은데 ㅜㅜ

    2024.01.26 02:43
    회원프로필

    저도 아직 걷는건 손으로 해요 ㅋㅋㅋ 걸어가면 범위 내에 몹 있을 때 자동공격하게..
    성공했는데 반응속도가 좀 느려서 수정하려다 엉켰네요 ㅜ

    2024.01.26 02:45

      게시글 리스트
      제목작성자작성일조회
      공지10-2022133
      6167701:03121
      6167611-14186
      6167511-14220
      6167411-14204
      6167311-14206
      6167211-13302
      6167111-13359
      6167011-13338
      6166911-13321
      6166811-13332
      6166711-13351
      6166611-13476
      6166511-12483
      6166411-12504
      6166311-12565
      6166211-11711
      6166111-11657
      6166011-11831
      6165911-11703
      안내 배너 이미지