BubiStu

Untitled

Feb 15th, 2025 (edited)
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | Gaming | 0 0
  1. local Players = game:GetService("Players")
  2. local LocalPlayer = Players.LocalPlayer
  3. local Camera = workspace.CurrentCamera
  4. local UserInputService = game:GetService("UserInputService")
  5. local RunService = game:GetService("RunService")
  6.  
  7. local aimEnabled = false
  8. local lockedPlayer = nil -- currently locked target
  9.  
  10. -- Create and configure the FOV drawing circle
  11. local fovCircle = Drawing.new("Circle")
  12. fovCircle.Color = Color3.fromRGB(255, 255, 255)
  13. fovCircle.Transparency = 0.7
  14. fovCircle.NumSides = 100
  15. fovCircle.Radius = 100
  16. fovCircle.Position = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2)
  17. fovCircle.Visible = true
  18.  
  19. -- Check if a player's character is within the FOV circle
  20. local function isPlayerInFOV(player)
  21. local character = player.Character
  22. if character and character:FindFirstChild("HumanoidRootPart") then
  23. local screenPosition, onScreen = Camera:WorldToScreenPoint(character.HumanoidRootPart.Position)
  24. if onScreen then
  25. local distance = (Vector2.new(screenPosition.X, screenPosition.Y) - fovCircle.Position).Magnitude
  26. return distance <= fovCircle.Radius
  27. end
  28. end
  29. return false
  30. end
  31.  
  32. -- Aim camera at the target player's HumanoidRootPart
  33. local function aimAtPlayer(player)
  34. local character = player.Character
  35. if character and character:FindFirstChild("HumanoidRootPart") then
  36. local targetPosition = character.HumanoidRootPart.Position
  37. local cameraCFrame = CFrame.new(Camera.CFrame.Position, targetPosition)
  38. Camera.CFrame = cameraCFrame
  39. end
  40. end
  41.  
  42. -- Teleport the local player's character behind the target player
  43. local function teleportBehindPlayer(targetPlayer)
  44. local targetCharacter = targetPlayer.Character
  45. local localCharacter = LocalPlayer.Character
  46. if targetCharacter and targetCharacter:FindFirstChild("HumanoidRootPart") and
  47. localCharacter and localCharacter:FindFirstChild("HumanoidRootPart") then
  48. local targetHRP = targetCharacter.HumanoidRootPart
  49. local offsetDistance = 5 -- distance behind the target
  50. -- Calculate behind position: subtract the target's LookVector scaled by offsetDistance
  51. local behindPosition = targetHRP.Position - (targetHRP.CFrame.LookVector * offsetDistance)
  52. -- Set local player's character CFrame so that it faces the target
  53. local newCFrame = CFrame.new(behindPosition, targetHRP.Position)
  54. localCharacter:MoveTo(behindPosition)
  55. -- Alternatively, you can set the CFrame directly:
  56. -- localCharacter.HumanoidRootPart.CFrame = newCFrame
  57. end
  58. end
  59.  
  60. -- Toggle aim and clear locked target when turning off
  61. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  62. if not gameProcessed and input.KeyCode == Enum.KeyCode.T then
  63. aimEnabled = not aimEnabled
  64. if not aimEnabled then
  65. lockedPlayer = nil
  66. end
  67. end
  68. end)
  69.  
  70. -- Main loop to update aim and teleportation
  71. RunService.RenderStepped:Connect(function()
  72. if aimEnabled then
  73. -- If no locked target, look for one within the FOV
  74. if not lockedPlayer or not (lockedPlayer.Character and lockedPlayer.Character:FindFirstChild("HumanoidRootPart")) then
  75. lockedPlayer = nil -- reset if invalid
  76. for _, player in ipairs(Players:GetPlayers()) do
  77. if player ~= LocalPlayer and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
  78. if isPlayerInFOV(player) then
  79. lockedPlayer = player
  80. break
  81. end
  82. end
  83. end
  84. end
  85.  
  86. -- If a target is locked, aim and teleport behind them continuously
  87. if lockedPlayer then
  88. aimAtPlayer(lockedPlayer)
  89. teleportBehindPlayer(lockedPlayer)
  90. end
  91. end
  92. end)
  93.  
  94. -- Update the FOV circle's position on the screen each frame
  95. RunService.RenderStepped:Connect(function()
  96. fovCircle.Position = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2)
  97. end)
Advertisement
Add Comment
Please, Sign In to add comment