Right now I am trying to implement a “aim assist” in my game.
right now it updates a vectorforce to apply force in the direction of a player onto a ball on RunService.Stepped
Right now it is just being tested with rolling balls on the floor but soon it’ll be implemented for thrown balls in air
I have to make the aim assist only help, not ever go past and ruin the players shots
it locks onto the closest player at the time to the ball that is able to be shot
Right now it does looping around the player in a “0” shape and overshoots
robloxapp-20231008-0751239.wmv (4.0 MB)
Heres the code
local CollectionService = game:GetService("CollectionService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
RunService.Stepped:Connect(function()
for _,Ball in pairs(CollectionService:GetTagged("Ball")) do
local FiredBy = Ball:GetAttribute("FiredBy")
local ClosestRoot
local ClosestDistance
for _,Player in pairs(Players:GetPlayers()) do
if FiredBy and FiredBy.Team then
if not FiredBy.Team:GetAttribute("FriendlyFire") then
if FiredBy.Team == Player.Team then
continue
end
end
end
if Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") then
if not ClosestDistance or ClosestDistance > (Ball.Position - Player.Character.HumanoidRootPart.Position).Magnitude then
ClosestRoot = Player.Character.HumanoidRootPart
ClosestDistance = (Ball.Position - Player.Character.HumanoidRootPart.Position).Magnitude
end
end
end
Ball.VectorForce.Force = Vector3.zero
if ClosestRoot then
Ball.VectorForce.Force = CFrame.lookAt(Ball.Position, ClosestRoot.Position).LookVector * script:GetAttribute("BallSpeed")
end
end
end)
BallSpeed is basically how much I want it to “assist”