Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

My mouse.Hit.p is inaccurate? How do I make the aim more precise or did I mess something up?

Asked by 4 years ago

When clicking, my script in a tool uses Target to make sure it is on a part. When it knows it's clicking a part, it goes on to use mouse.Hit.p to create a ray. The ray then makes sure that the part it hits is named after what I want it to be named, and then it fires an event. But, for some odd reason I cant wrap my head around I have to hold my mouse slightly above the part not on it, any explanation as to why or some other methods I could use that function easier or something?

Clip of the problem : https://gyazo.com/054208b4f6f8593b6ced986dfc15f920

The script in the tool:

01local Players = game:GetService("Players")
02local localPlayer = game.Players.LocalPlayer
03local PartTransRequest = game.ReplicatedStorage:WaitForChild("PartTransRequest") -- event for making part transparent
04 
05 
06-- grab the mouse
07local mouse = localPlayer:GetMouse() -- get mouse
08local target = mouse.Target -- get mouse target to check if its clicking a part
09 
10 
11Equipped = false -- so the code doesnt repeat when its not equipped
12 
13script.Parent.Equipped:connect(function()
14    Equipped = true
15end)
View all 51 lines...

1 answer

Log in to vote
0
Answered by
Elyzzia 1294 Moderation Voter
4 years ago
Edited 4 years ago

when you use Ray.new, the second argument is an offset from the origin

to convert a position in world space to position's local space (which in this case is the origin's), you can just do b - a

1local lookDirection = mouse.Hit.p - rayOrigin

also, you should consider changing to the new raycasting api, since FindPartOnRay is deprecated

the documentation for it is here https://developer.roblox.com/en-us/api-reference/function/WorldRoot/Raycast

Ad

Answer this question