Fix the object to the ground

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)

1 Like

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

1 Like

Could you simplify it better?, I don’t have many experiences with RayCast

Sure, do you have any code I can show you with?

You can do any one, so I can study mine, unfortunately I had to delete it to try to understand more how it could be done.:no_mouth::confused:, (If you want, of course)

1 Like
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

1 Like

Oh, Thank you very much, this will last me a long time, I will study more on this🌟

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.