Skip to content
Jackie edited this page Jul 2, 2021 · 9 revisions

Table of Contents

Introduction

rayCastHitboxRbxl is a hit detection system that utilizes Roblox's Raycasting APIs.

The module is written entirely in Roblox Lua and requires no additional dependencies.

The goal of this module is to provide an accurate and fast alternative to melee (and in some cases ranged) hit detection without the need to rely on physics based touch systems which are often unreliable.

Example Usage

Basic Tool Example

local Player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Tool = script.Parent
local RaycastModule = require(RaycastHitboxV4)

--- Create the hitbox for our tool
local Hitbox = RaycastModule.new(tool)

--- Create raycast points for our tool
Hitbox:SetPoints(Tool.Handle, {Vector3.new(1, 0, 0), Vector3.new(5, 0, 0), Vector3.new(10, 0, 0)}) --- Alternatively you can use attachments instead

--- Create RaycastParams to ignore our character so we don't accidentally damage ourselves
local RaycastParams = RaycastParams.new()
RaycastParams.FilterDescendantsInstances = {Character}
RaycastParams.FilterType = Enum.RaycastFilterType.Blacklist

--- Set our Hitbox's RaycastParams to the one we just created
Hitbox.RaycastParams = RaycastParams

--- Create our Touch function
function OnTouch(hit, humanoid)
    print(hit.Name)
    humanoid:TakeDamage(25)
end

--- What happens when we activate our tool?
function OnActivation()
    Hitbox:HitStart() --- Starts the hit detection
    wait(10) --- Wait a few seconds
    Hitbox:HitStop() --- Stops the hit detection
end

--- Event listeners
Hitbox.OnHit:Connect(OnTouch)
Tool.Activated:Connect(OnActivation)

Check out Getting Started for more examples.

Links

Welcome

Getting Started

Documentation

Clone this wiki locally