I am trying to make a rig follow the player from behind. What I made works well in one direction, but once you start rotating, it gets really messed up. This is what happens when you rotate the character.
I am trying to make it stay behind the player, even when it rotates.
I have tried to find some articles about this, but I’ve never found any who’d help me in this specific situation.
The rig’s HumanoidRootPart has the BodyPosition and BodyGyro, and all the parts are welded.
(This is the code inside the script, if it helps)
while wait(.1) do
script.Parent.BodyPosition.Position = game.Workspace.Player.HumanoidRootPart.Position - game.Workspace.Player.HumanoidRootPart.CFrame.LookVector - Vector3.new(-2,0,2)
script.Parent.BodyGyro.CFrame = game.Workspace.Player.HumanoidRootPart.CFrame
end
How could I make it stay behind the player, no matter how it rotates?
Thanks!
Interesting. This topic might be useful. You would want to consider wrapping this in a RunService.Heartbeat connection as well instead of an infinite loop.
Also, I wanted to point out that you can’t assign CFrame values to BodyMovers. Only position. You can get a Vector3 value from a CFrame by simply doing CFrame.Position.
In your case, AlignPosition would be a better choice than BodyPosition. Create a constraint, parent it to the HumanoidRootPart of the player’s character and change its position so it’s around where you’d want the second character to be located. Create a second constraint, parent it to the second character’s HumanoidRootPart. Create the AlignPosition constraint, parent it to one of the characters’ HumanoidRootParts and apply the Attachment0 and Attachment1 properties.
One thing to note is that the second character might get stuck on obstacles, so you’ll have to check each frame whether it is too far away and fix its location if it’s too far away.
One thing to note is that the second character might get stuck on obstacles, so you’ll have to check each frame whether it is too far away and fix its location if it’s too far away.
The second character is CanCollide = false, so it shouldn’t be a problem.
Also, for the Constraint, what should I use? WeldConstraints, attachments?
I don’t want the second character to walk, I want it to be kind of stuck to the player in that position. Also, the second character doesn’t have humanoid.
I created 2 attachments, one on the player and one on the second character, then set the attachment0 and attachment1 of the AlignPosition to them and it still didn’t work, the character just falls to the ground.
Do I need to script or anchor something?
Sorry if I’m missing something obvious, these things are a real pain for me.