TargetSurface Alternatives

I am currently creating a block placement system, However when I hover my block over a base part that is rotated, then the block’s offset will be off as you can see in the video below. This is because Mouse.TargetSurface can be inaccurate if a base part is rotated. I’d like to know if there are any alternatives for Mouse.TargetSurface.

Uploading: 2023-07-27 11-36-56.mp4…

Here is a portion of my script that is used to calculate the blocks offset


	-------Block Offsets
	
	if Mouse.TargetSurface == Enum.NormalId.Top then
		Block.Position = Block.Position + Vector3.new(0,Offset,0)
		
	elseif Mouse.TargetSurface == Enum.NormalId.Back then
		Block.Position = Block.Position + Vector3.new(0,0,Offset)
		
	elseif Mouse.TargetSurface == Enum.NormalId.Right then
		Block.Position = Block.Position + Vector3.new(Offset,0,0)
		
	elseif Mouse.TargetSurface == Enum.NormalId.Bottom then
		Block.Position = Block.Position - Vector3.new(0,Offset,0)
		
	elseif Mouse.TargetSurface == Enum.NormalId.Front then
		Block.Position = Block.Position - Vector3.new(0,0,Offset)
		
	elseif Mouse.TargetSurface == Enum.NormalId.Left then
		Block.Position = Block.Position - Vector3.new(Offset,0,0)

	end




I would recommend using raycasts. This is because the raycast will return a Normal Vector, which is the way the face of the part that was hit is pointing. You can orient the part to the normal vector, then move it up half of its height. (This assumes you’re working with cubes.)

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