I trying to make goalkeeper ball targeting system like this:
But when i tested out my targeting system i getting this:
I tried to add some boolean checks but its not helped at all
Theres a block of code that i have issue with:
local ballPos: Vector3 = ballModel:GetPivot().Position
local primaryPos: Vector3 = self.Model.PrimaryPart.Position
local homePos: Vector3 = self.homePosition.Position
if (ballPos - primaryPos).Magnitude <= 40 and BallController:GetBallPhysic().resting then
self:InterceptBall()
end
if (ballPos - primaryPos).Magnitude <= self.catchRange then
self:InterceptBall()
else
if BallController:GetCaptured() ~= "" then
if (self.homePosition.Position - primaryPos).Magnitude > 15 then
self.Model:PivotTo(self.homePosition)
return
end
local ballZPos = ballPos.Z
local faceCf = CFrame.new(primaryPos.X, primaryPos.Y, ballZPos)
local finalCf = faceCf * CFrame.Angles(0, math.rad(90), 0)
self.Model:PivotTo(finalCf)
end
end
I assume you’re trying to get the keeper to stay within the bounds of the net, so use math.clamp() to clamp the position of the goalkeeper within the bounds of the net, your code seems to find the final position the keeper should be, and if its out of the net bounds, you just reset the keepers cframe to the home position, so instead of that, just clamp the final cframe