Mouse.hit.p ignoring everything

The problem is just as stated in the title. For some reason, no matter what I point at on my screen, my mouse is ignoring it, and it seems like my mouse.hit.p keeps returning some position from the void. I’m not exactly sure what’s actually being returned by mouse.hit, but it’s just that my fireball script seems to send the fireball to some position in the void rather than a wall or block that the mouse is hovering over, and it’s supposed to send the fireball to the mouse.Hit.Position. If anyone knows what the problem might be or think they can help me, that would be great, please.

mouse.Hit.p (now deprecated, in favour of mouse.Hit.Position) is the mouse’s CFrame, not what it’s pointing at. It sounds like you want to get what the mouse is pointing at. Use mouse.Target for this.

1 Like

Oh okay, I never knew this. Thank you, rookie mistake I guess haha.

1 Like

Wait ok so actually, went back and tried, and that’s not exactly what I mean. Ok so you see, let’s say I for example point my mouse to the corner of a wall, then I shoot my fireball. Instead of going to the corner of the wall, my fireball goes past it towards some direction in the void. Do you know how I would make it go to the corner of the wall instead?

You should provide the script you’re having an issue with.

If you’re using mouse.Target that returns the part, not the position of where you’re aiming towards. Use mouse.Hit.Position instead.

If you want to avoid the issue where your aim “snaps” when aiming from distant to closer objects, I’d recommend using mouse.UnitRay.Direction

You’re gonna need raycasting, something along the lines of what @SkrubDaNub said.

--LocalScript
local uis = game:GetService("UserInputService")

local cam = workspace.CurrentCamera

local location = uis:GetMouseLocation()
local ray = cam:ScreenPointToRay(location.X, location.Y, --[[depth number here]])

local params = RaycastParams.new() --do whatever you want to the params here
local hit = workspace:Raycast(ray.Origin, ray.Direction, params)
if hit then
    --do stuff when the fireball hits the edge
end
3 Likes

this is even better - the mouse object is pretty limiting anyway.

1 Like

It’s probably going to be deprecated soon

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