0% found this document useful (0 votes)
31 views3 pages

Message 30

The document contains a Lua script designed for a game, which implements a targeting system for players. It includes settings for prediction, smoothing, and adjustments for jumping and falling. The script utilizes user input to toggle targeting and adjusts the camera position based on the targeted player's movement and velocity.

Uploaded by

disponial
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views3 pages

Message 30

The document contains a Lua script designed for a game, which implements a targeting system for players. It includes settings for prediction, smoothing, and adjustments for jumping and falling. The script utilizes user input to toggle targeting and adjusts the camera position based on the targeted player's movement and velocity.

Uploaded by

disponial
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

getgenv().prediction = 0.

31
getgenv().offset = 0
getgenv().resolver = false
getgenv().smoothness = 0.120

getgenv().JumpAdjustment = 3.6
getgenv().FallAdjustment = 1.9
getgenv().JumpSmoothing = 0.07
getgenv().FallSmoothing = 0.07

local players = game:GetService("Players")


local localplayer = players.LocalPlayer
local mouse = localplayer:GetMouse()
local userinputservice = game:GetService("UserInputService")
local runservice = game:GetService("RunService")
local currentCamera = workspace.CurrentCamera

local victim = nil


local targeting = false

local function target()


local target = nil
local shortdistance = math.huge

for _, v in next, workspace:GetDescendants() do


if v.Parent and v:IsA("Model") and v ~= localplayer.Character then
if v:FindFirstChildOfClass("Humanoid") then
if v:FindFirstChildOfClass("Humanoid").Health > 0 then
pcall(function()
local worldtoviewportpoint, onscreen =
currentCamera:WorldToViewportPoint(v:FindFirstChildOfClass("Humanoid").RootPart.Pos
ition or v.PrimaryPart.Position)
local distance = (Vector2.new(mouse.X, mouse.Y) -
Vector2.new(worldtoviewportpoint.X, worldtoviewportpoint.Y)).Magnitude
if math.huge > distance and distance < shortdistance and
onscreen then
target = v
shortdistance = distance
end
end)
end
end
end
end
return target and (target.PrimaryPart or
target:FindFirstChildOfClass("Humanoid").RootPart)
end

userinputservice.InputBegan:Connect(function(input, processed)
if processed then
return
end

if input.KeyCode == Enum.KeyCode.E then


targeting = not targeting
if targeting then
victim = target()
else
if victim ~= nil then
victim = nil
end
end
end
end)

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


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

runservice.Heartbeat:Connect(function(deltaTime)
if victim and victim.Parent then
local currentpos = victim.Position
local displacement = currentpos - oldpos

local vector = displacement / deltaTime

velocity = velocity:Lerp(Vector3.new(
vector.X,
vector.Y * 0.94 * getgenv().offset,
vector.Z
), 0.4)

oldpos = currentpos
end
end)

runservice.RenderStepped:Connect(function()
local pos

if targeting and victim and victim.Parent then


if victim.Parent:FindFirstChildOfClass("Humanoid") then
if victim.Parent:FindFirstChildOfClass("Humanoid").Health > 0 then
local humanoid = victim.Parent:FindFirstChildOfClass("Humanoid")
local yVelocity = humanoid.RootPart.Velocity.Y

if getgenv().usePrediction then
if getgenv().resolver then
pos = Vector3.new(
victim.Position.X,
victim.Position.Y,
victim.Position.Z
) + (velocity * getgenv().prediction)
else
pos = Vector3.new(
victim.Position.X,
victim.Position.Y,
victim.Position.Z
) + (victim.Velocity * getgenv().prediction)
end
else
pos = Vector3.new(
victim.Position.X,
victim.Position.Y,
victim.Position.Z
)
end

local smoothness = getgenv().smoothness


if yVelocity > 1 then
pos = pos + Vector3.new(0, getgenv().JumpAdjustment, 0)
smoothness = getgenv().JumpSmoothing
elseif yVelocity < -1 then
pos = pos + Vector3.new(0, -getgenv().FallAdjustment, 0)
smoothness = getgenv().FallSmoothing
end

currentCamera.CFrame =
currentCamera.CFrame:Lerp(CFrame.new(currentCamera.CFrame.Position, pos),
smoothness)
end
end
end
end)

You might also like