Hitbox API - Swordphin/raycastHitboxRbxl GitHub Wiki

Properties

RaycastParams RaycastParams

Returns information about the current HitboxObject's RaycastParams. Writing to this property with your own RaycastParam settings will also change the way the raycasting works.

boolean Visualizer

If true, turns on the visualizer for the raycasts to see where you are aiming them. Highly recommended to leave it off for production games to conserve performance.

boolean DebugLog

If true, writes print logs to the output. Things like if it can find attachments will be recorded.

number DetectionMode

Notice
This parameter only accepts a value between 1 - 3. Writing a value above 3 will default to Bypass DetectionMode.

Defaults to RaycastHitbox.DetectionMode.Default (1). Determines how the hit detection of the hitbox should be applied. Refer down below to all different types of DetectionModes.

  • Default (1) - Checks if a humanoid exists when this hitbox touches a part. The hitbox will not return humanoids it has already hit for the duration the hitbox has been active.

  • PartMode (2) - OnHit will return every hit part (in respect to the hitbox's RaycastParams), regardless if it's ascendant has a humanoid or not. OnHit will no longer return a humanoid so you will have to check it. The hitbox will not return parts it has already hit for the duration the hitbox has been active.

  • Bypass (3+) - PERFORMANCE MAY SUFFER IF THERE ARE A LOT OF PARTS. Use only if necessary. Similar to PartMode, the hitbox will return every hit part. Except, it will keep returning parts even if it has already hit them. Warning: If you have multiple raycast or attachment points, each raycast will also call OnHit. Allows you to create your own filter system.

number SignalType

Notice
This parameter only accepts a value between 1 - 2. Writing a value above 2 will default to Single.
Notice 2
RaycastHitbox.SignalType.Default can introduce memory leaks if used incorrectly. Remember to destroy the hitbox or disconnect the listener when it is no longer needed.

Defaults to RaycastHitbox.SignalType.Single (2). Determines how the signal behaviour should be applied. Refer down below to all different types of SignalTypes.

  • Default (1) - Acts similarly to RBXScriptSignal. If you need to listen to the hitbox from multiple scripts or entities, OnUpdate/OnHit will fire to all listeners (in the order that they are hooked to).

  • Single (2) - Default behaviour of RaycastHitbox due to legacy purposes. OnUpdate/OnHit accepts only one listener. OnUpdate/OnHit will ignore and garbage collects any old listeners and only fires to the most recent listener.

Functions

void SetPoints ( basePart | bone instance, table vector3Points, string groupName )

Merges existing Hitbox points with new Vector3 values relative to the part / bone position.

This part can be a descendent of your original Hitbox model or can be an entirely different instance that is not related to the hitbox (example: Have a weapon with attachments and you can then add in more vector3 points without instancing new attachments, great for dynamic hitboxes).

Optional Parameter
groupName: When specified, if these points hit something, OnHit will return the same groupName parameter, allowing you to do different things depending on where your weapons hit.

void RemovePoints ( basePart | bone instance, table vector3Points )

Removes the given Vector3 values provided the part was the same as the ones you set in SetPoints.

void LinkAttachments ( attachment attachment1, attachment attachment2 )

Specifies two attachments to be connected like a link. The Raycast module will raycast between these two points instead of following each frame.

void UnlinkAttachments ( attachment attachment1 )

Removes a link of an attachment. Only needs the primary attachment (first parameter of LinkAttachments) to work. Will automatically sever the connection to the second attachment.

void HitStart ( number seconds )

Starts firing the rays for hit detection. Will only damage the target once. Call HitStop to reset the target pool so you can damage the same targets again. If HitStart hits a target(s), OnHit event will be called. Can specify an optional argument in seconds for the module to automatically turn off the Hitbox after 'N' seconds.

void HitStop ()

Stops firing the rays and resets the target pool. Will do nothing if no rays are being fired from the hitbox.

void Destroy ()

Disables the hitbox, cleans up all internal signals, sets itself to nil and marks it for garbage collection to be deleted in the next frame. It will also be automatically called if the object used for hitboxes (if specified initially) is destroyed.

Events

RBXScriptSignal OnHit ( basePart hitPart, humanoid hitHumanoid, raycastResult results, string groupName )

Notice
If your hitbox's DetectionMode is not on Default, hitHumanoid will return nil. It is your responsibility to check if the humanoid exists.
Notice 2
OnHit supports only one connection at this time. Connecting OnHit multiple times will overwrite its current functionality with the most recent one (not the normal stacking ability like normal Roblox connections support). This was made to ensure that developers do not need to worry about disconnecting their OnHits. You can change this functionality in the Signals script.

Fires when a part intersects a raycast. Will return the part it hits plus any raycast results. It will also return the point's groupName (nil by default).

RBXScriptSignal OnUpdate ( Vector3 pointPosition )

When a hitbox is active, fires for every point on every frame, returning a point's current position in the world.