Outline Block doesn't follow mouse position

Hello, my building system is working so far, but I’m attempting to create a block outline that follows my mouse. It’s purpose is to show the player what the block will look like before they place it. However, it does not properly follow my mouse and I’m not sure why.

RunService.RenderStepped:Connect(function()
	newBlock.Position = Mouse.Hit.p
end)

Once the block moves to Mouse.Hit.p, the value of Mouse.Hit.p changes to the top of the block as it’s been updated. The block will become out of place and start rising towards the camera if you don’t lock the Y value of the position

OHH, that makes sense, so what I can do is lock the Y position to the Mouse Target’s Y position + 1 stud or however I want. So like this:

RunService.RenderStepped:Connect(function()
	newBlock.Position = Vector3.new(Mouse.Hit.p.X, Mouse.Target.Position.Y, Mouse.Hit.p.Z)
end)

Yea but I recommend forcing a specific Y value if it’s for a placement system like a sandbox game, otherwise just using Mouse.Target,Size.Y/2 + newBlock.Size.Y/2 to make it appear at the top works perfectly fine

1 Like

I’m just wondering how this algorithm works too.

Update: nevermind I figured it out

There’s an issue with this algorithm, Since the Baseplate’s size on the Y-axis is 16 and my block’s size on the Y-axis is 3, then Mouse.Target.Size.Y/2 = 8 and newBlock.Size.Y/2 = 1.5, adding these together gets me 9.5(or 10 if you wanna round up), which means that I have an outline that is ten studs above the mouse position. How can I fix this?

try and make it mouse.Target.Position + ThisSizeVectorThingY2Stuff

but the Y shouldn’t be changed by mouse.Hit.p

I’m confused by you’re saying. Could you please provide a direct example?