What i want:
-
What do you want to achieve? Teleportation of the ball to BallStarterPos (It’s a part in workspace) without any movement during the process.
-
What is the issue? When the ball is teleported the Vector Force i use for kicking it seems to still apply.
-
What solutions have you tried so far? I tried anchoring and then unachoring the ball but it still results in the same way.
So bassicaly i am making a FootBall game, really simple and all, where ofc you kick the ball into a Goal, but my problem is when i Kick the ball into the Goal i want it to Teleport to BallStarterPos.Position, it teleports fine but the force that i used for Kicking the Ball is still Applying, meaning that when i teleport the ball it rushes in the same direction as kicked.
Here is the Script for teleporting the Ball:
local Players = game.Players
local BlueScore = workspace.BlueScore
local RedScore = workspace.RedScore
local Ball = workspace.Ball
local BallStarterPos = workspace.BallStarterPos
local BlueTeam = game.Teams.Blue
local RedTeam = game.Teams.Red
BlueScore.Touched:Connect(function(Hit)
if Hit == Ball then
BlueTeam.Goals.Value += 1
Ball.Position = BallStarterPos.Position
end
end)
RedScore.Touched:Connect(function(Hit)
if Hit == Ball then
RedTeam.Goals.Value += 1
Ball.Position = BallStarterPos.Position
end
end)
Here is the script that apply the Vector Force:
local ball = script.Parent
local RS = game:GetService("ReplicatedStorage")
local KickEvent = RS.Events.KickEvent
local function isLooking(hrp, ball, angleThreshold)
local lookVector = hrp.CFrame.LookVector
local facing = Vector2.new(lookVector.X, lookVector.Z).Unit
local ballPos = Vector2.new(ball.Position.X, ball.Position.Z)
local hrpPos = Vector2.new(hrp.Position.X, hrp.Position.Z)
local dir = (ballPos - hrpPos).Unit
local angle = math.acos(facing:Dot(dir))
local deg = math.deg(angle)
if deg < angleThreshold then
return true
else
return false
end
end
local function isWithinRange(hrp, ball, tolerance)
return (hrp.Position - ball.Position).Magnitude < tolerance
end
KickEvent.OnServerEvent:Connect(function(player)
local Char = player.Character or player.CharacterAdded:Wait()
local hrp = Char:WaitForChild("HumanoidRootPart")
local rngFlg = isWithinRange(hrp, ball, 6)
local lookFlg = isLooking(hrp, ball, 75)
if rngFlg and lookFlg then
local dir = (ball.Position - hrp.Position).Unit
local att = Instance.new("Attachment", ball)
local force = Instance.new("VectorForce", ball)
force.Attachment0 = att
force.RelativeTo = Enum.ActuatorRelativeTo.World
force.Force = dir * 1000
force.ApplyAtCenterOfMass = true
game.Debris:AddItem(force, .2)
game.Debris:AddItem(att, .2)
end
end)
Video of the Problem (Sorry for the Lag):
Thank you for your time