I have been making a gun but was trying to figure out which is to use. Using a ray from the tool to the mouse position or use a ray on the bullet’s lookVector with a 1.5 studs ray with run service.
Also any help on the new ray system since the old one is should not be used.
I’d prefer the old raycast which you get the unit of the mouse and the tool’s fire part, get the hit and position of the result of the raycast “workspace:FindPartOnRay(ray, table, bool, bool)”.
You then get the distance of the tool’s fire part and the position variable from the previous line, you can use the hit to check if it hits a specific part using print(), my bad if what i said was simple since i didn’t understand much but if that was all you needed then good.
I’d prefer the old one than the new one since you know i’m different, but you can try out the new type if you’re curious, i only recommend what i like.
The new raycasting system is a lot better and I find it simpler.
Step 1:
First call the RayCast() function with the Vector3 Origin and Direction
local RayResult = workspace:Raycast(Origin, Direction)
This article was a big help for me, it also gives to formula for getting the direction if you only have the origin and destination:
This is important because when making a weapon you have the origin, which is the gun and the destination which is the players mouse hit.
Step2:
If the ray didn’t intersect something it will return nil so you have to have an if statement:
local RayResult = workspace:Raycast(Origin, Direction)
if RayResult then
end
Step 3:
The info you have is this:
local RayResult = workspace:Raycast(Origin, Direction)
if RayResult then
print(RayResult.Instance.Name)
end
Could you add more things on the whitelist and blacklist for the new one? Since doing it on the old one requires a table which I do not know how to do.
I didnt mention RayCastParameters, you use that
Where would I add the ray, on the bullet or the tool?
Also I tried raycast on a bullet but it won’t damage the player.