Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my model sunken down to the ground?

I made a model follow my mouse cursor in a script, but the model seems to be a bit sunken down to the ground?

Here is the script that I made:

local Part = game.Workspace:WaitForChild("Model")

Mouse.Move:Connect(function()
	Part:SetPrimaryPartCFrame(CFrame.new(Mouse.Hit.p)*CFrame.Angles(0,math.rad(CurrentRot),0))
	Mouse.TargetFilter = Part
end)

Is it because of modeling stuff? Or is it the script?

1 comment

0

What do you mean by sunken? But it might need to be Anchored. (Select the model go into properties scroll down until you see "Anchored" and tick it)

1 answer

✓ Accepted answer

It's because the Mouse.Hit is hitting the ground, so the position you are setting Part to is being set to the ground. For example, if we say the Baseplate is at y = 0, then the Mouse.Hit's y component will also be 0.

The Vector3 position of the object is located at the center of a part, so you are setting the center of your model to be the ground, meaning the lower half of your model will be sunk underground.

If I had a Part which I wanted to set the position to be flat on the ground, I would add half of the height to the position I am setting it to - for example:

local Part = workspace:FindFirstChild("Part")

Mouse.Move:Connect(function()
	Part.Position = Mouse.Hit.p + (Part.Size.Y / 2)
	Mouse.TargetFilter = Part
end)

Hope this helps.

4 comments

0

Lemme try

0

How would I do this on a model instead?

0

The idea is similar but the difference is that a Part has a specified height, a Model's height is unknown. However, since you are using SetPrimaryPartCFrame, if you always make the PrimaryPart in the model the lowest part, then you can add half of that part's size.

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.