Error with raycasting

For some reason ive been trying to make this placement system. I was raycasting to see if it would collide with objects and stuff but for some reason the object never moves to the mouses position. Anyone know why?

								if placingobject == true then
									mouse.TargetFilter = previewobject
									if previewobject:FindFirstChild("MainPart") then
										local ignoreList = {game.Players.LocalPlayer.Character}
										if previewobject ~= nil then
											table.insert(ignoreList,previewobject)
										end
										local mouseRay = mouse.UnitRay
										local newRay = Ray.new(mouseRay.Origin, mouseRay.Direction.Unit * 35)
										target, pos, norm = workspace:FindPartOnRayWithIgnoreList(newRay, ignoreList)
									end
								else
									previewobject:Destroy()
								end
								if placingobject == false then
									script.Parent.Inventorybtn.Visible = true
									script.Parent.Rotation.Visible = false
								end
							end)
3 Likes

can you show a video on whats happening

1 Like

i think you should be using camra cframe position instead of the mouseray orgin

1 Like

There is nothing really to show its just the object never moves

1 Like

Are there any errors in the output? What are you using to move the object?

2 Likes

no But I found a problem I forgot to set the primarypartsCFrame. Can you help me turn this code into something that precents the previewobjects from clipping into walls?

								if placingobject == true then
									mouse.TargetFilter = previewobject
									if previewobject:FindFirstChild("MainPart") then
										local objectcframe = CFrame.new(math.round(mouse.Hit.Position.X/grid)*grid,math.round(mouse.Hit.Position.Y+previewobject.PrimaryPart.Size.Y/2), math.round(mouse.Hit.Position.Z/grid)*grid)
										local objectangles = CFrame.Angles(0, math.rad(rotationamount), 0)
										previewobject:SetPrimaryPartCFrame(objectcframe*objectangles)
									end
								else
									previewobject:Destroy()
								end
								if placingobject == false then
									script.Parent.Inventorybtn.Visible = true
									script.Parent.Rotation.Visible = false
								end
							end)```

are u talking about a gridding system? or just something that prevents clipping?

I already made the grid system I just need help with the things not touching

Precise bound checking
Box bound checking
Radius bound checking

I’m sorry but this doesn’t work and it is too convoluted. It is also not for bound checking but just a snapping system.

thanks for the corrections tho i was just worse at scripting back then so i just had to use alternative methods so it is scuffed

Thank you so much that was the solution!

1 Like

Thank you for helping! I found the solution!

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