How can I keep this brick at a certain distance from the head?

I made a script to place a brick on the opposite side of the player’s head from the camera.

https://gyazo.com/dff112f65cf4d63695071a82e6a6143a

The issue is, I don’t want the distance from the brick to player change. How can I make the brick stay at a set distance from the player?

local RE = workspace.REs.RemoteEvent_PCD
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()

while wait(.1) do
	local camera = workspace.CurrentCamera
	local camera_pos = camera.CFrame.Position
	local head_pos = character.Head.Position
	
	local difference = camera_pos - head_pos
	
	local camera_invertedpos = head_pos - difference
	
	RE:FireServer(camera_invertedpos) --sends to the server to change bricks position
end

Use the unit vector of difference and then multiply that by the distance that you want the brick to be.

2 Likes

I’m not sure what you mean. I tried:

local difference = (camera_pos - head_pos) * 5

but that’s clearly not what you meant.

A unit vector is a normalized copy of the vector. It’s direction is the same but the magnitude of it is only one. You can add that to your code by doing the following:

local difference = (camera_pos - head_pos).unit * 5
2 Likes

You could use the LookVector of the head and multiply it by how many studs ahead you want the brick to be, then add to the part’s current position