I have spent a few hours now, thinking how to do this.
How do I place a model at the camera with the z position offset by 5, but rotation stays 0?
I know it has something to do with object space, but I don’t have the knowledge to know how to use it.
I’m also trying to learn a bit more about this, so please also explain your answers if possible!
(I know one rule is not to make people write whole systems for me, but i cant really find the answer i need on the internet.)
I want the part you are going to place in a building system to show up like Minecraft for instance. I have most done, but I don’t like how the part/model’s rotation is the same as the camera rotation. So, I want the rotation to stay as 0,0,0 or any other chosen rotation.
also, i want the z-coordinate to be offset by like 6 studs so it isn’t straightly attached to the camera, but i think thats the root of the problem, because it just goes in the same direction no matter the cam orientation, as i think it moves in the world space
function showItem(item)
lastitem = currentitem
currentitem = item.Name
if game.ReplicatedStorage.Game.Items:FindFirstChild(itemdataModule[returneddata[tostring(game.Players.LocalPlayer.UserId)]["InventoryData"][selecteditem]["ItemID"]]) then
if len(returneddata[tostring(game.Players.LocalPlayer.UserId)]["InventoryData"][selecteditem]) < 1 then
if game.Workspace.CurrentCamera:FindFirstChild("ItemShown") then
game.Workspace.CurrentCamera:FindFirstChild("ItemShown"):Destroy()
end
else
if currentitem == lastitem then
local cam = game.Workspace.CurrentCamera
local model = cam:FindFirstChild("ItemShown")
model:PivotTo(cam.CFrame)
else
local model = item:FindFirstChild("Model")
if game.Workspace.CurrentCamera:FindFirstChild("ItemShown") then
game.Workspace.CurrentCamera:FindFirstChild("ItemShown"):Destroy()
end
local newmodel = model:Clone()
newmodel.Name = "ItemShown"
newmodel.Parent = workspace.CurrentCamera
end
end
end
end
lastitem currentitem are for detecting if the selected item is changed
-- Get the camera
local cam = workspace.CurrentCamera
-- Get its position from the CFrame, and offset it by 2 on Z
local pos = cam.CFrame.Position * Vector3.new(0,0,2)
local model -- Your model
model:PivotTo(CFrame.new(pos))
Or, you could do something more hacky, like do :PivotTo() on a model with the camera’s original CFrame, then, do :PivotTo() on the unrotated model with the position of the rotated. that was a mouthful