Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- local localPlayer = Players.LocalPlayer
- local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
- local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
- local targetPlayerName = "TargetUsername" -- Change this to the player you want to copy
- local targetCharacter = nil
- local targetRootPart = nil
- local lastPosition = nil
- local lastVelocity = nil
- local lastUpdateTime = tick()
- local smoothingFactor = 15 -- Higher means smoother transitions
- local function findTarget()
- local targetPlayer = Players:FindFirstChild(targetPlayerName)
- if targetPlayer and targetPlayer.Character then
- targetCharacter = targetPlayer.Character
- targetRootPart = targetCharacter:FindFirstChild("HumanoidRootPart")
- lastPosition = targetRootPart.Position
- lastVelocity = targetRootPart.Velocity
- end
- end
- local function predictTargetPosition()
- if not targetRootPart then return end
- local currentTime = tick()
- local timeElapsed = currentTime - lastUpdateTime
- local predictedPosition = targetRootPart.Position + (targetRootPart.Velocity * timeElapsed)
- lastPosition = targetRootPart.Position
- lastVelocity = targetRootPart.Velocity
- lastUpdateTime = currentTime
- return predictedPosition
- end
- RunService.RenderStepped:Connect(function(deltaTime)
- if not targetRootPart then findTarget() end
- if not targetRootPart then return end
- local predictedPosition = predictTargetPosition()
- humanoidRootPart.Position = humanoidRootPart.Position:Lerp(predictedPosition, deltaTime * smoothingFactor)
- end)
Advertisement
Add Comment
Please, Sign In to add comment