How to maintain position of a model relative to HumanoidRootPart?

I have a model which I PivotTo() according to the HumanoidRootPart of the player, but I don’t know how to maintain its position relative to the HRP. How do I do this? (I know I have to use To Object/World Space but not sure how)

Are you sure you cannot just weld the part to the HumanoidRootPart?

1 Like

I tried that. Although it didn’t work because the model kept falling to the void (CanCollide off)

If it is client side, than you can use RunService.RenderStepped to constantly update the position, adding the original distance between the part and the player to the HumanoidRootPart's CFrame.

I’m busy, I’ll be back soon to help.

Yeah, it’s the client side. The problem is that the model spawns randomly around the player and I don’t know how to keep track of that position, without altering it, only on the X/Z and Y positions.

Weld all parts in the model to it’s primarypart, then weld the primarypart to the HRP. This way it won’t fall into the void.

All the parts of the model are welded through Motor6Ds and WeldConstraints. Not even that worked.

Could you provide a .rblx file with the problem and the code you have tried so far?

Anchor the primarypart, if it still falls down then it isn’t properly welded.

If it doesn’t fall, then there must be an issue with your weld to the HRP

Anchoring it makes the model to not fall down.

Welding is made on the client, and the part that the weld needs to follow is moved RenderStepped-edly to the HumanoidRootPart.

file.rblx.rbxl (64.0 KB)
I’ve wrote some test codes but deleted it since it wouldn’t work.
Script:

function module.attack()
	local Character = Player.Character
	local Head = Character.Head
	local Model = ModelUnused:Clone()
	
	RunService:BindToRenderStep("StalkRenderWeld",Enum.RenderPriority.Camera.Value,renderPart)
	if not RendererWeldPart then
		repeat
			Model.Renderer.Value = RendererWeldPart
			RunService.RenderStepped:Wait()
		until
		RendererWeldPart
	end
	Model.Renderer.Value = RendererWeldPart	
	
	local fieldOfView = Camera.FieldOfView/2
	local YAngle = math.random(fieldOfView, 360-fieldOfView)
	local XAngle = math.random(fieldOfView, 360-fieldOfView)
	local Angle = CFrame.Angles(math.rad(XAngle),math.rad(YAngle),0)
	local CamCFrame = Camera.CFrame
	local Offset = Character.HumanoidRootPart.CFrame.LookVector * 3
	local Position = Character.HumanoidRootPart.CFrame * Angle * Offset
	
	local PositionCFrame = CFrame.new(Position)
	
	Model:PivotTo(PositionCFrame)
	Model.PrimaryPart.CFrame = CFrame.lookAt(Model.PrimaryPart.Position,Head.Position)
	
	RunService:BindToRenderStep("RenderStalkMine",Enum.RenderPriority.Camera.Value,function()
		-- attempts tried
	end)
	Model.Parent = workspace
end

I’ll try to give you a working .rblx file soon

1 Like

Is this what you’re going for? I have the updating system down it doesn’t use welds. I just don’t know what you’re wanting exactly…

There is some issues in lag that you can hopefully fix, it seems to only have after the ticking starts, which may mean that it is in the Handler module. I’m not sure. Here’s the file:
fixed.rbxl (64.5 KB)

This is what :ToObjectSpace() is good for!

When the bottom line happens:

Model:PivotTo(PositionCFrame)
Model.PrimaryPart.CFrame = CFrame.lookAt(Model.PrimaryPart.Position,Head.Position)

I want to maintain that position. I am currently trying ToWorldSpace with offsets, but I don’t think that would work

What behavior are you going for? I made it so that the part maintains the position relative to the HumanoidRootPart's CFrame. Please elaborate.

If you know the game “Doors”, I’m trying to mimic Screech’s behavior. Following your head without rotating with it, only Positioning.

Okay, I’ll see what I can do.
But you still want it to move with the player, just not rotate with it?

1 Like

Yeah, exactly like Screech. No rotation, just positioning on the XYZ axises.

After some trial and error, I got it working.

As you can see, it now does not rotate.

The solution I used was not the cleanest, but it works…

local x,y,z,r00,r01,r02,r10,r11,r12,r20,r21,r22 = Model.PrimaryPart.CFrame:components()
		
local Renderer = Model -- NOT SURE WHAT YOU'RE GOING FOR, CHANGE THIS PART TO WHAT YOU WANT!
		
Model.Renderer.Value = Model

local Difference = Model.PrimaryPart.CFrame:ToObjectSpace(HRP.CFrame)

RunService:BindToRenderStep("RenderStalkMine",Enum.RenderPriority.Camera.Value,function()
	print("still bound")
	if Model ~= nil then 
		local newPos = HRP.CFrame * Difference
		newPos = newPos.Position
		local newCFrame = CFrame.new(newPos.X,newPos.Y,newPos.Z,r00,r01,r02,r10,r11,r12,r20,r21,r22)
		Model.PrimaryPart.CFrame = newCFrame
	end
end)

Here’s the file:
fixed.rbxl (64.6 KB)

I hope you find this useful! :slight_smile:

Thanks! I’ll change some things to match my preference, but I appreciate that you helped me!

There are still some lag problems, I hope you can sort them out.