How to omit the mouse from hitting parts except baseplate

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to achieve the mouse not hitting parts except the baseplate

  2. What is the issue? Include screenshots / videos if possible!
    the mouse hits every part it touches, making moving or interacting very difficult in an isometric camera.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    none, because my issue doesn’t exist on the forums

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

The Code:

--//Player Look//--
local target = Mouse.Hit.p
local newYTarget = hrp.Position.Y -- Keep the Y position of the root part
hrp.CFrame = CFrame.lookAt(hrp.Position, Vector3.new(target.X, newYTarget, target.Z))

(note, hrp is humanoid root part.)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

You should look into raycasting - you can utilize the RaycastParams to only include certain parts in workspace

local rayOrigin = camera.CFrame.Position
local rayDirection = mouse.Hit.Position
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {baseplate} – Put objects to exclude here
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = true
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)

And then you get your part like this below:

local partThatWasHit = raycastResult.Instance

You could also utilize “Enum.RaycastFilterType.Include” instead of Exclude if it’s easier to include the “good” parts than to exclude the “bad” ones

so how would i be able to use cframe:lookat with this? sorry about this but i have never touched raycasting before. also, to clarify, i want to only hit the baseplate.

Hello, like what @Physicism said, you need to use raycasting to omit or whitelist parts that you want your mouse to hit. I’ll show you how I would do this

local mouseray = mouse.UnitRay -- Ray fired from cam to mouse
local raycastparams = RaycastParams.new()
raycastparams.FilterDescendantsInstances = {workspace.Baseplate}
raycastparams.FilterType = Enum.RaycastFilterType.Include -- Ray will only detect if it hits the baseplate
local ray = workspace:Raycast(mouseray.Origin,mouseray.Direction,raycastparams)
if ray then -- If ray hit the baseplate
   local raypos = ray.Position --[[Every ray has this property
which determines the position of intersection between hitpart
and ray]]
   local hrpypos = hrp.Position.Y
   hrp.CFrame = CFrame.lookAt(hrp.Position,Vector3.new(raypos.X,hrpypos,raypos.Z))
end

thanks for the reply, unfortunetly, it isn’t exactly working. there are no errors that show up in the console.

Check my script for any spelling mistakes to comply with the variables you declared. Also this should be a local script

to confirm, it is a local script. here is the entire code

RunService:BindToRenderStep("MoveOverride", Enum.RenderPriority.Character.Value + 1, function()
	if Player.Character then
		Camera.FieldOfView = FieldOfView
		local humanoid = Player.Character:FindFirstChild("Humanoid")
		local hrp = Player.Character:FindFirstChild("HumanoidRootPart")
		if humanoid and hrp then
			--//Humanoid Movement.//--
			local characterCFrame = hrp.CFrame
			local fixedDirection = Vector3.zero
			local inputDirection = getInputDirection()
			if inputDirection ~= Vector3.zero then
				fixedDirection = characterCFrame:VectorToWorldSpace(inputDirection)
			end
			humanoid:Move(fixedDirection, false)
			
			--//Isometric Camera//--
			game:GetService("SoundService"):SetListener(Enum.ListenerType.ObjectCFrame, Character.HumanoidRootPart)
			Camera.CFrame = CFrame.new(Vector3.new(Character.HumanoidRootPart.Position.X + zoom, Character.HumanoidRootPart.Position.Y + zoom, Character.HumanoidRootPart.Position.Z + zoom), Character.HumanoidRootPart.Position)
			
			--//Player Look//--
			local mouseray = Mouse.UnitRay -- Ray fired from cam to mouse
			local raycastparams = RaycastParams.new()
			raycastparams.FilterDescendantsInstances = {workspace.Baseplate}
			raycastparams.FilterType = Enum.RaycastFilterType.Include -- Ray will only detect if it hits the baseplate
			local ray = workspace:Raycast(mouseray.Origin,mouseray.Direction,raycastparams)
			if ray then -- If ray hit the baseplate
				local raypos = ray.Position --[[Every ray has this property
				which determines the position of intersection between hitpart
				and ray]]
				local hrpypos = hrp.Position.Y
				hrp.CFrame = CFrame.lookAt(hrp.Position,Vector3.new(raypos.X,hrpypos,raypos.Z))
			end
		end
	end
end)

(the player look is where i have placed your code at.)

Could you send me a vid of the problem? Because it’s hard for me to tell what’s the issue from here

if i try to send a vid my pc either lags and the video is of shit quality or doesn’t give me the video entirly. my pc, a ASUS vivobook, has the computer proccessing power of a slice of asparagus.

Ah that’s sad, can you write out the problem here then in detail so I wring my brain out

so. whenever i start the game, it loads like you expect, no errors in the console. however, instead of the character following the mouse, it just doesn’t rotate, since i have Humanoid.AutoRotate = false.

Try changing this to local ray = workspace:Raycast(mouseray.Origin,mouseray.Direction.Unit * 1000,raycastparams)

does the *1000 signify how long the ray goes?

Yes it does. Let me break down mouseray.Direction.Unit * 1000 for you
UNIT
What unit does is basically shorten the given Vector3 to a magnitude (length) of 1 while still retaining the direction of the Vector3. So unit is very useful to produce a small Vector3 for you to change
*1000
Since we used .Unit to shorten the direction to a length of 1, we are free to extend it to a length of our choice. The number can be anythjng, but I picked 1000 here since its a nice number :slight_smile:

so it can be Math.huge. i just hope my pc don’t go le poopoo :D!

unfortunately you can’t, because the max limit for a raycast distance is 15,000 studs.

eh, knew someone would correct me. the more i know :person_shrugging:

1 Like

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