{"id":"egomoose/raycast-helper","name":"raycast-helper","scope":"egomoose","platform":"roblox","description":"https://github.com/EgoMoose/raycast-helper","version":"3.0.1","latest":"3.0.1","versions":["0.1.1","0.1.2","0.2.0","1.0.0","2.0.0","2.1.0","3.0.0","3.0.1"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"fc8cdb3b498fe5e83df1d499e235e87335d526fd6b332b16eaf43ef4b9a0d234","likes":0,"downloads":0,"install":"forest install egomoose/raycast-helper","url":"https://forest.dev/p/roblox/egomoose/raycast-helper","files":"https://api.forest.dev/ai/package/roblox/egomoose/raycast-helper/files","readme":"# Raycast Helper\r\n\r\nA simple module for ray and shape casting with complex filtering.\r\n\r\nGet it here:\r\n\r\n* [Wally](https://wally.run/package/egomoose/raycast-helper)\r\n* [Releases](https://github.com/EgoMoose/raycast-helper/releases)\r\n\r\n## Raycast callbacks\r\n\r\nEvery cast function in the module allows for an optional \"filter\" argument. This function can be used to write custom filters for a specific cast in addition to the built in functionality from `Enum.RaycastFilterType`.\r\n\r\n```Luau\r\nlocal CollectionService = game:GetService(\"CollectionService\")\r\n\r\nlocal function exampleFilter(result: RaycastResult, cancel: () -> ())\r\n\tlocal hit = result.Instance :: BasePart\r\n\r\n\tif CollectionService:HasTag(hit, \"castCancel\") then\r\n\t\t-- at any point we can cancel the cast attempt which closes the thread and leaves the final result as nil\r\n\t\tcancel()\r\n\tend\r\n\r\n\t-- otherwise, return a boolean\r\n\t-- if true, we will accept this raycast result\r\n\t-- if false, we will not accept this raycast result and will add the instance and its descendants to the exclusion list\r\n\treturn hit.CanCollide\r\nend\r\n```\r\n\r\n## Example\r\n\r\nIn this example a ray is casted and only parts that have `Transparency == 0` are considered as valid candidates for the ray to hit.\r\n\r\n```Luau\r\nlocal function mustBeFullyVisible(result: RaycastResult)\r\n\tlocal hit = result.Instance :: BasePart\r\n\treturn hit.Transparency == 0\r\nend\r\n\r\nlocal mouseRay = getMouseRay()\r\nlocal result = RaycastHelper.raycast({\r\n\torigin = mouseRay.Origin,\r\n\tdirection = mouseRay.Direction * 999,\r\n\r\n\trayParams = RaycastHelper.rayParams({\r\n\t\tfilterType = Enum.RaycastFilterType.Include,\r\n\t\tinstances = {},\r\n\t})\r\n\r\n\tfilter = mustBeFullyVisible,\r\n})\r\n```\r\n\r\n## API\r\n\r\n```Luau\r\ntype GeneralCastOptions = {\r\n\tworldRoot: WorldRoot?,\r\n\trayParams: RaycastParams?,\r\n\tfilter: ((RaycastResult, () -> ()) -> boolean)?,\r\n}\r\n\r\ntype RaycastOptions = GeneralCastOptions & {\r\n\torigin: Vector3,\r\n\tdirection: Vector3,\r\n}\r\n\r\ntype BlockcastOptions = GeneralCastOptions & {\r\n\tcframe: CFrame,\r\n\tsize: Vector3,\r\n\tdirection: Vector3,\r\n}\r\n\r\ntype SpherecastOptions = GeneralCastOptions & {\r\n\tposition: Vector3,\r\n\tradius: number,\r\n\tdirection: Vector3,\r\n}\r\n\r\ntype ShapecastOptions = GeneralCastOptions & {\r\n\tpart: BasePart,\r\n\tcframe: CFrame?,\r\n\tdirection: Vector3,\r\n}\r\n\r\nfunction module.raycast(options: RaycastOptions): RaycastResult?\r\nfunction module.blockcast(options: BlockcastOptions): RaycastResult?\r\nfunction module.spherecast(options: SpherecastOptions): RaycastResult?\r\nfunction module.shapecast(options: ShapecastOptions): RaycastResult?\r\n\r\ntype RaycastParamOptions = {\r\n\tinstances: { Instance }?,\r\n\tfilterType: Enum.RaycastFilterType?,\r\n\tignoreWater: boolean?,\r\n\tcollisionGroup: string?,\r\n\trespectCanCollide: boolean?,\r\n\tbruteForceAllSlow: boolean?,\r\n}\r\n\r\nfunction module.params(options: RaycastParamOptions): RaycastParams\r\n```","readmeBorrowedFrom":{"version":"2.0.0","source":"wally"},"readmeTruncated":false}