Games like Lumber Tycoon 2 have a placement system, and if you were to place a conveyor in Lumber Tycoon 2 on the side of another one, they would align perfectly. How can I do that with mine, NOT using surfaces or raycasting, and just the mouses target? my placement system already works just not aligning. Also my first post so it might be not that good.
TO prevent errors exactly like this
if I were to try to place it on the side of the conveyor, it would go inside conveyor because I don’t know how to implement the system in the title
place Code:
RunService.RenderStepped:Connect(function()
if CurrentModel and Mouse.Target then
local Primary = CurrentModel.PrimaryPart
local Pos = Mouse.Hit.Position+Vector3.new(0,0,0)
Pos = Vector3.new(
math.floor(Pos.X / gridSize + 0.5) * gridSize,
math.floor(Pos.Y / gridSize + 0.5) * gridSize,
math.floor(Pos.Z / gridSize + 0.5) * gridSize
)
CurrentModel:SetPrimaryPartCFrame(CFrame.new(Pos+Vector3.new(0,CurrentModel:GetExtentsSize().Y/2,0))*CFrame.Angles(0,math.rad(CurrentRotationY),0))
end
end)
I am trying to make the object align to the surface of the mouses target. Like Lumber Tycoon 2. In that game you can see that when you place an object on a surface it aligns on top or in front and never inside the surface.
Ok I understand, why not use raycasting?
I see that in your title you don’t want to use raycasting but I’m wondering why? Is it because you don’t understand raycasting, if you don’t why not just learn how to use it? Whatever the reason its pretty hard to think of a way to align the parts position to on top of whatever you want without using a raycast or shapecast.
I’m not sure why you don’t want to use raycasting. It returns a normal, and an instance that it touched, it’s way easier. Is it just a pet peeve? Or for some other functional reason?
If there is a way I can use raycasting, then I will do it if it is the only way. For both you and @Den_vers I can use raycasting, I just didn’t want to use it since I have no idea how to use it on this type of thing.
If you don’t know how to use Raycasting I recommend dropping what your doing right now and going to learn it there are a bunch of tutorials online on Youtube and the Devforum ill send some links:
Also with the system your asking us to make, are you asking us to create you a system that simply aligns parts based on their position to each other, if so really just use raycasting
I will use raycasting. I already have created gun system and did other things with raycasting, I just am not sure for this particular problem how I can do it.
Don’t use :SetPrimaryPartCFrame(), it’s deprecated. Use :PivotTo(). If you want to get the target use mouse.Target. To align it, I would get the position of the part (assuming it’s a sphere or square) and multiply it by half the width of the target, and half the width of the part being placed. Like this:
local part = path.to.part
-- after raycast
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Include
raycastParams.FilterDescendantInstances = {} -- list of parts (and descendants) to include in search
local raycast = workspace:Raycast(
camera.Position,
(camera.Position - mouse.Hit.CFrame) * 10,
raycastParams)
if raycast then
local normal = raycast.Normal
part.CFrame = raycast.Position + (normal * part.Size.X)
end
It’s a rough draft, try it out. I’m also making the assumption that part.Size.X is the axis that will be facing the other part.
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {CurrentModel}
local raycast = workspace:Raycast(
Camera.CFrame.Position,
(Mouse.Hit.Position - Camera.CFrame.Position) * 10,
raycastParams)
if raycast then
print("Yes6")
local normal = raycast.Normal
CurrentModel:PivotTo(CFrame.new(raycast.Position + (normal * CurrentModel:GetExtentsSize().X)))
end
Also if you only do X axis, does that mean the model is only gonna align on X axis? I would want all axis to align on. So far it aligns just offset some shown in picture above.
Yeah, you’ll have to check the rotation of the object, I’m not sure what system you have in place for that. Determine which axis to use based on the rotation.