I’m working on a positioning simplifier, I have everything in order and working normally because this part is simple, but I was confused in performing the fusion of fixing the object to the ground, for example:
When a person wants to put the object in place instead of the object floating, it should be placed fixed on the ground and not floating above it.
How would I accomplish this task?
(I'm not using "GetMouse()" from Client, but positioning in front of the character)
Maybe raycast down from the object, then when it hits the ground surface get it’s position and move the model to that position + half the size of the model
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
local localPlayer = Players.LocalPlayer
local mouse = localPlayer:GetMouse()
mouse.Button1Down:Connect(function()
local character = localPlayer.Character
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {character}
local raycastResult = workspace:Raycast(character:GetPivot().Position, Vector3.fromNormalId(Enum.NormalId.Bottom) * 10, raycastParams)
if raycastResult then
local part = Instance.new("Part") --Just creating a part
part.Anchored = true
part.Size = Vector3.new(5, 3, 5)
part.CanCollide = false
part.Color = Color3.new(math.random(), math.random(), math.random())
part.CFrame = CFrame.new(raycastResult.Position + Vector3.new(0, part.Size.Y/2, 0))
part.Parent = workspace
Debris:AddItem(part, 3)
end
end)
Put this code in a LocalScript in StarterPlayer → StrarterPlayerScripts. Basically every time you click your mouse, it creates a part on the ground where the player is standing. If you have any questions about it lmk