Calculated Y Offset for Building System

Assuming that your raycast is at the mouse’s position you can just reuse the math:

  local RayHit = CFrame.new(Raycast.Position)
  local Target = Raycast.Instance
  local RayRelative = RayHit:ToObjectSpace(Target.CFrame):Inverse()
	
GhostPart.Position = Target.Position + Vector3.new(0, GhostPart.Size.Y/2 + Target.Size.Y/2, 0) + (RayRelative.Position * Vector3.new(1,0,1))

Although I still dont understand why you are using a raycast, instead of just Mouse.Hit

1 Like

Yes, you simply just need the part that the mouse is targeting as well as the position that the ghost part is moved to.

This is what I meant, the changes were not that complex.

There is still a gap in between the platform and the rock, code is below:

local instance = raycastresult.Instance
local RayHit = CFrame.new(raycastresult.Position)
local RayRelative = RayHit:ToObjectSpace(instance.CFrame):Inverse()
					
local EndPos = instance.Position + Vector3.new(0, placeHolder.PrimaryPart.Size.Y/2 + instance.Size.Y/2, 0) + (RayRelative.Position * Vector3.new(1,0,1))
placeHolder.PrimaryPart.Position = EndPos

The rock’s mesh is probably smaller than the actual part, what’s the bounds for it?

I believe this is what your wanting, right?

local model = workspace:WaitForChild("Model")

while true do
	local mouse = game:GetService("UserInputService"):GetMouseLocation()
	local ray = workspace.Camera:ViewportPointToRay(mouse.X, mouse.Y)
	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Exclude
	params.FilterDescendantsInstances = {model}
	local result = workspace:Raycast(ray.Origin, ray.Direction * 1000, params)
	
	if result then
		local MouseHit = CFrame.new(result.Position)
		local Target = result.Instance
		local MouseRelative = MouseHit:ToObjectSpace(Target.CFrame):Inverse()
		
		local cf, size = model:GetBoundingBox()
		local yOffset = size.Y/2
		
		model:PivotTo(CFrame.new(Target.Position + Vector3.new(0, yOffset + Target.Size.Y/2, 0) + (MouseRelative.Position * Vector3.new(1,0,1))))
	end
	
	task.wait()
end

make sure your code looks similar to this and reset the model’s pivot

I am doing exactly that, but I am setting its position, because if not the rock is rotated.

Set the pivot and like I said, reset the pivot because it’s incorrect rn.

As I said, when I set the Pivot, the rock is rotated 45 degrees, and that looks not good

You didn’t say Pivot you said Position, and did you reset the model’s pivot?

And how do I do this?
sdfsdfsdf

Click the model then click this

image

I reset the pivot, and the rock is still rotated in placing mode.


Also, when I do place it, there is still a gap

Could you send a file of the rock so I can check some things.

RockFile.rbxm (4.2 KB)

As expected, its because of the bounding box of the rock. That model isn’t really fit for any kind of solution I can think of.

Fixed Rock Pivot Model.rbxm (19.0 KB)

I had to re-union the parts because of the way unions work with pivots in roblox, more info here: How to edit pivots or center uneven Unions? - #3 by Unarthadoxx, but this should have a fixed pivot now.

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