BodyPosition is correct, but part goes to wrong position

So, I have a bodyPosition. It is set to the correct value, but the part is at the wrong position.

It should follow the player, but when the player stops the part instead of being to it’s left is to it’s right, behind, in front, you name it.

How can I fix this?

2 Likes

Can you add the script it’s easier to help that way

Just a loop that constantly updates the BodyPosition’s Position, the bodyPosition is right, the part itself is not

local humRootPart = character.HumanoidRootPart

local bodyGyro = script.Parent.PrimaryPart.BodyGyro
local bodyPos = script.Parent.PrimaryPart.BodyPosition

while wait() do   
	bodyPos.Position = humRootPart.Position + Vector3.new(2, 2, 3)
	bodyGyro.CFrame = humRootPart.CFrame
end

You always want the part to be next to the player?

Yes, the bodyPosition is always next to the player, just not the part

So like this?

1 Like

Yes exactly, but the problem is that the part “drifts” when the player stops, it doesnt stop where it should

Ok, i just made a script like this

-- Code

while wait() do
game.Workspace.PartFollow.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,4)
end

So the part is behind me

You just need to change the last CFrame(“What the position is”)

I tried this but it is wonky, the part shakes a lot specially when turning.

1 Like

Have you tried to weld it? So it doesn’t shake?

If you haven’t just weld it to the HumanoidRootPart

But I want it to have a smooth feel to it, accelerating and decelerating smoothly.

I’m sorry but i don’t know how to do that. If i find out i will message you, I hope you will find out how to do it

are you looking for something to keep it aligned (Edited to remove gif sry)

I think so, I want it to smoothly change speeds instead of being instant

in that gif I was using alignposition and alignorientation along with a custom attachment that i add in characteradded. this is how my studio looked and here is the script i used:

game.Players.PlayerAdded:Connect(function(v)
	v.CharacterAdded:Connect(function(d)
		game.ServerStorage.Part.PartAttachment:Clone().Parent = d:WaitForChild('Head')
       local ao = Instance.new('AlignOrientation', d:WaitForChild('Head'))
       local ap = Instance.new('AlignPosition', d:WaitForChild('Head'))
	    ao.Attachment0 = workspace.Part.Attachment
	    ao.Attachment1 = d:WaitForChild('Head'):WaitForChild('PartAttachment')
	    ap.Attachment0 = workspace.Part.Attachment
		ap.Attachment1 = d:WaitForChild('Head'):WaitForChild('PartAttachment')
	end)
end)

(script is kinda messy cause i was just doing it manually in studio but does show how to do it)

2 Likes

Hi!

The reason this is happening is because the positioning along the vectors isn’t correlating with the Players position.

I’d recommend using Humanoid.CFrame.LookVector * -2 and Humanoid.CFrame.RightVector * -2. I’m away at the moment so unable to test.

But using this method will mean that the BodyPosition is constantly directly behind the Players HumanoidRootPart & constantly to the Right of the Players HumanoidRootPart, no matter what direction they are looking!

Hope this helps, feel free to ask anymore questions.

With answers above, you can use RunService.Heartbeat for smoothness :eyes:

Hope this helps!
v
v
v

local Player = game:GetService("Players").LocalPlayer
repeat wait(.05) until Player.Character ~= nil
local Character = Player.Character

local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local Follower = Instance.new("Part")
Follower.Parent = game:GetService("Workspace")

local BodyPosition = Instance.new("BodyPosition")
BodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BodyPosition.Parent = Follower

local BodyGyro = Instance.new("BodyGyro")
BodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
BodyGyro.Parent = Follower

game:GetService("RunService").Heartbeat:Connect(function()
	BodyGyro.CFrame = HumanoidRootPart.CFrame
	BodyPosition.Position = HumanoidRootPart.Position + HumanoidRootPart.CFrame.LookVector * -5 + HumanoidRootPart.CFrame.RightVector * -2
end)
1 Like