local EndPos = raycastresult.Position + Vector3.new(0,placeHolder:GetExtentsSize().Y/2,0)
Current code that I have right now, :GetExtentsSize() works better, but as seen in the above image there is still a gap.
local EndPos = raycastresult.Position + Vector3.new(0,placeHolder:GetExtentsSize().Y/2,0)
Current code that I have right now, :GetExtentsSize() works better, but as seen in the above image there is still a gap.
How would I implement it with raycasts?
Instead of mouse pos, you would get the ray cast position.
If you want to not use Mouse then you can use ViewportPointToRay and raycast
I am using a UnitRay using UserInputService to RayCast, does that have the properties I need to use @Haystees’s solution?
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
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?
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
I reset the pivot, and the rock is still rotated in placing mode.
Could you send a file of the rock so I can check some things.