Looking to make a placement system for tools just like this, where it’ll preview where you place it and whether or not you can put it down, and not too sure how to go about it.
This is kind of the gist of how I would do it
Get the part/mesh and create a new instance of it and change its transparency to 0.9 (or however much you want) and removing the texture (if any) and setting it to blue (or whichever color highlight you want it)
Then shoot a raycast from the camera with a distance of 6 studs(or however you want it).
If raycast is nil then place the part/mesh 6 studs from the player based on the cameras look vector
else get the hit position of the raycast and place the part/mesh there
Then you can just get the rotation of the camera and set it to the part/mesh. Or if you want you could make it turn 45 degrees when pressing a key to turn the part/mesh, (however you want to do it)
Then if you are going to switch to a different tool/thing then just destroy the part
will try build off this, thanks
Will the part only be on the ground? if thats the case then you should shoot a raycast downwards and also shoot it 6 studs away from the player, then get the hit location and place the part there. Give the raycast some height so it can detect different elevation.
As for whether or not you want to make it not placeable at different spots then you need to create a boundingbox and check if that part(the one that was created) is in the boundingbox.
Another method would be to check the raycast result if the material/texture/model/mesh/part/etc… is something you dont want it on and make it not placeable.
yeah i’m looking to make something that can just be put on the floor, like a claymore or a bear trap.
Here is the code if this helps
--!native
--!strict
task.wait(3)
-- Includes
local RunService=game:GetService("RunService");
-- Player related
local player = game:GetService("Players").LocalPlayer
local playerCharacter = player.Character or player.CharacterAdded:Wait();
local playerHRP = playerCharacter:WaitForChild("HumanoidRootPart");
-- Create instance of part
local previewPart = Instance.new("Part", game.Workspace);
previewPart.Size = Vector3.new(8,8,1);
previewPart.Transparency = 0.9;
previewPart.Color = Color3.fromRGB(0, 255, 255)
previewPart.CanCollide = false;
previewPart.CanQuery = false;
previewPart.Anchored = true;
local function previewPlacement()
local distanceFromPlayer = CFrame.new(playerHRP.CFrame.LookVector * 6) * CFrame.new(0,3,0) * playerHRP.CFrame;
local distance = Vector3.new(distanceFromPlayer.Position.X,distanceFromPlayer.Position.Y - 32,distanceFromPlayer.Position.Z) - distanceFromPlayer.Position;
local raycast = game.Workspace:Raycast(distanceFromPlayer.Position, distance);
if raycast then
previewPart.Position = raycast.Position;
previewPart.Orientation = playerHRP.Orientation;
end
end
RunService.PreRender:Connect(function()
previewPlacement();
end)
yea this works great, i can definitely build off it. thanks
I updated the code cause there were some errors.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.