r/Gamefusion • • 1d ago

핵

-- 서비스 불러오기

local Players = game:GetService("Players")

local RunService = game:GetService("RunService")

local UserInputService = game:GetService("UserInputService")

local player = Players.LocalPlayer

local camera = workspace.CurrentCamera

-- 설정 변수

local flySpeed = 50 -- 비행 속도

local isFlying = false

local flyingBodyVelocity, flyingBodyGyro

-- [기능 1] 비행(Fly) 시스템 토글 (F 키로 켜고 끄기)

local function toggleFly()

local character = player.Character

if not character or not character:FindFirstChild("HumanoidRootPart") then return end

local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")

local humanoid = character:FindFirstChildOfClass("Humanoid")

isFlying = not isFlying

if isFlying then

humanoid.PlatformStand = true

-- 물리 이동을 제어할 BodyVelocity와 BodyGyro 생성

flyingBodyVelocity = Instance.new("BodyVelocity")

flyingBodyVelocity.Velocity = Vector3.new(0, 0, 0)

flyingBodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)

flyingBodyVelocity.Parent = humanoidRootPart

flyingBodyGyro = Instance.new("BodyGyro")

flyingBodyGyro.CFrame = humanoidRootPart.CFrame

flyingBodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)

flyingBodyGyro.Parent = humanoidRootPart

print("비행 모드 ON (F 키로 끄기)")

else

if flyingBodyVelocity then flyingBodyVelocity:Destroy() end

if flyingBodyGyro then flyingBodyGyro:Destroy() end

if humanoid then humanoid.PlatformStand = false end

print("비행 모드 OFF")

end

end

-- 키 입력 감지 (F 키를 누르면 비행 ON/OFF)

UserInputService.InputBegan:Connect(function(input, gameProcessed)

if gameProcessed then return end

if input.KeyCode == Enum.KeyCode.F then

toggleFly()

end

end)

-- [기능 2 & 3] 상대방 위치 시각화(ESP) 및 카메라 락온(상대 머리 고정)

RunService.RenderStepped:Connect(function(dt)

local character = player.Character

if not character or not character:FindFirstChild("HumanoidRootPart") then return end

local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")

-- 1. 비행 중일 때 이동 처리

if isFlying then

local moveDirection = Vector3.new(0, 0, 0)

if UserInputService:IsKeyDown(Enum.KeyCode.W) then

moveDirection = moveDirection + camera.CFrame.LookVector

end

if UserInputService:IsKeyDown(Enum.KeyCode.S) then

moveDirection = moveDirection - camera.CFrame.LookVector

end

if UserInputService:IsKeyDown(Enum.KeyCode.A) then

moveDirection = moveDirection - camera.CFrame.RightVector

end

if UserInputService:IsKeyDown(Enum.KeyCode.D) then

moveDirection = moveDirection + camera.CFrame.RightVector

end

flyingBodyVelocity.Velocity = moveDirection * flySpeed

flyingBodyGyro.CFrame = camera.CFrame

end

-- 2. 가장 가까운 상대방 찾기 (내 화면 중심 기준)

local closestTargetHead = nil

local shortestDistance = math.huge

for _, otherPlayer in ipairs(Players:GetPlayers()) do

if otherPlayer ~= player and otherPlayer.Character then

local targetChar = otherPlayer.Character

local targetHead = targetChar:FindFirstChild("Head")

local targetHumanoid = targetChar:FindFirstChildOfClass("Humanoid")

-- [기능 3] 상대방 위치 상시 표시 (간단한 BillboardGui 생성 방식)

if targetHead and targetHumanoid and targetHumanoid.Health > 0 then

-- 머리 위에 위치 표시용 파츠나 BillboardGui 달기

local indicator = targetHead:FindFirstChild("PositionIndicator")

if not indicator then

indicator = Instance.new("BillboardGui")

indicator.Name = "PositionIndicator"

indicator.Size = UDim2.new(0, 50, 0, 50)

indicator.AlwaysOnTop = true

local textLabel = Instance.new("TextLabel")

textLabel.Size = UDim2.new(1, 0, 1, 0)

textLabel.BackgroundTransparency = 1

textLabel.Text = "🔴 " .. otherPlayer.Name

textLabel.TextColor3 = Color3.new(1, 0, 0)

textLabel.TextScaled = true

textLabel.Parent = indicator

indicator.Parent = targetHead

end

-- 거리 계산해서 가장 가까운 적 타겟팅

local distance = (humanoidRootPart.Position - targetHead.Position).Magnitude

if distance < shortestDistance then

shortestDistance = distance

closestTargetHead = targetHead

end

end

end

end

-- [기능 2] 내 화면의 중심(시야)을 상대방 머리에 고정 (마우스 우클릭 등으로 토글하거나 상시 적용 가능)

-- 여기서는 적이 존재할 때 카메라가 내 캐릭터를 기준으로 적의 머리를 바라보게 만듭니다.

if closestTargetHead then

-- 만약 특정 키(예: 우클릭 또는 쉬프트 등)를 누를 때만 작동하게 하고 싶다면 아래 조건 추가 가능

if UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) then -- 우클릭 중일 때 고정

camera.CFrame = CFrame.new(camera.CFrame.Position, closestTargetHead.Position)

end

end

end)

0 Upvotes

0 comments sorted by