Hello, I’m trying to make a sphere part that sort of acts like a curve when it’s going to it’s target, using BodyPosition. It’s working well so far, except for the fact that the bodypostion’s poisition is always 0,0,0 even though I’m setting it to something else:
local backpart = workspace.Part
local target;
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
target = character:FindFirstChild("HumanoidRootPart")
end)
end)
repeat wait() until target
while wait() do
-- print('x') -- prints
local mag_from_backpart = (backpart.Position - script.Parent.ball.Position).Magnitude
local mag_from_target = (target.Position - script.Parent.ball.Position).Magnitude
if mag_from_backpart <= 5 then
script.Parent.BodyPosition.Position = Vector3.new(target.CFrame:VectorToObjectSpace(script.Parent.ball.Position))
elseif mag_from_target <= 5 then
script.Parent.BodyPosition.Position = Vector3.new(backpart.CFrame:VectorToObjectSpace(script.Parent.ball.Position))
else
script.Parent.BodyPosition.Position = Vector3.new(target.CFrame:VectorToObjectSpace(script.Parent.ball.Position))
end
end
It would also be helpful if someone could direct me to another resource for accomplishing this, because this method doesn’t seem very useful and it feels hard to script. Thank you
I don’t know what you’re going to do with this script but here I fixed it
local Players = game:GetService("Players")
local backpart = workspace:FindFirstChild("Part")
local ball = workspace:FindFirstChild("ball")
local target
local function onCharacterAdded(character)
target = character:FindFirstChild("HumanoidRootPart")
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
while wait() do
if target then
local mag_from_backpart = (backpart.Position - ball.Position).Magnitude
local mag_from_target = (target.Position - ball.Position).Magnitude
if mag_from_backpart <= 5 then
ball.BodyPosition.Position = target.Position
elseif mag_from_target <= 5 then
ball.BodyPosition.Position = ball.Position
else
ball.BodyPosition.Position = target.Position
end
end
end