--// Construct & Init
local Caster = FastCast2.new() -- Construct a new Caster
Caster:Init(
numWorker: number, -- Number of worker VMs. Must be > 1.
newParent: Folder, -- Parent Folder for the FastCastVMs Folder.
newName: string, -- Name for the FastCastVMs Folder.
ContainerParent: Folder, -- Parent Folder for worker VM Containers.
VMname: string, -- Name given to each worker VM.
useBulkMoveTo: boolean, -- Enable BulkMoveTo for CosmeticBulletObjects.
FastCastEventsModule: ModuleScript, -- ModuleScript returning a FastCastEvents table.
useObjectCache: boolean, -- Enable ObjectCache for this Caster.
Template: BasePart | Model, -- Template object for ObjectCache (if enabled).
CacheHolder: Instance -- Parent Instance for cached objects (if enabled).
)
-- ⚠ Must be called before any Fire methods — nothing happens without Init!
--// Fire Methods
Caster:RaycastFire(
origin: Vector3,
direction: Vector3,
velocity: Vector3 | number,
BehaviorData: FastCastBehavior?
) → () -- Fire a raycast projectile.
Caster:BlockcastFire(
origin: Vector3,
Size: Vector3,
direction: Vector3,
velocity: Vector3 | number,
BehaviorData: FastCastBehavior?
) → () -- Fire a blockcast projectile.
Caster:SpherecastFire(
origin: Vector3,
Radius: number,
direction: Vector3,
velocity: Vector3 | number,
BehaviorData: FastCastBehavior?
) → () -- Fire a spherecast projectile.
--// Configuration
Caster:SetFastCastEventsModule(moduleScript: ModuleScript) → ()
-- Set a new FastCastEventsModule for all future BaseCasts from this Caster.
Caster:SetBulkMoveEnabled(enabled: boolean) → ()
-- Toggle BulkMoveTo for cosmetic bullet CFrame updates.
Caster:SetObjectCacheEnabled(
enabled: boolean, -- Toggle ObjectCache on/off.
Template: BasePart | Model, -- Projectile template to cache.
CacheSize: number, -- Number of objects to pre-allocate.
CacheHolder: Instance -- Where cached objects are stored.
) → ()
--// Cast Manipulation (use Caster reference, not cast itself)
Caster:GetPositionCast(cast: vaildcast) → Vector3 -- Current position of the cast.
Caster:GetVelocityCast(cast: vaildcast) → Vector3 -- Current velocity of the cast.
Caster:GetAccelerationCast(cast: vaildcast) → Vector3 -- Current acceleration of the cast.
Caster:SetVelocityCast(cast: vaildcast, velocity: Vector3) → () -- Override velocity.
Caster:SetAccelerationCast(cast: vaildcast, acceleration: Vector3) → () -- Override acceleration.
Caster:AddPositionCast(cast: vaildcast, position: Vector3) → () -- Add to current position.
Caster:AddVelocityCast(cast: vaildcast, velocity: Vector3) → () -- Add to current velocity.
Caster:AddAccelerationCast(cast: vaildcast, acceleration: Vector3) → () -- Add to current acceleration.
-- ⚠ After any Set/Add call, sync changes or they won't take effect in the VM:
Caster:SyncChangesToCast(cast: vaildcast) → () -- Push pending state changes to the worker VM.
Caster:PauseCast(cast: vaildcast) → () -- Pause simulation for a cast.
Caster:ResumeCast(cast: vaildcast) → () -- Resume a previously paused cast.
Caster:TerminateCast(cast: vaildcast) → () -- Forcefully terminate a cast early.
--// Lifecycle
Caster:Destroy() → () -- Destroy the Caster and clean up all resources.
--// Fields
-- Signals (assign a callback OR connect an RBXScriptConnection)
Caster.LengthChanged: (RBXScriptConnection | OnLengthChangedFunction)?
-- Fired every simulation step with: cast, segmentOrigin, segmentDirection, length, segmentVelocity, cosmeticBullet
Caster.Hit: (RBXScriptConnection | OnHitFunction)?
-- Fired when the cast hits something (non-piercing): cast, raycastResult, segmentVelocity, cosmeticBullet
Caster.Pierced: (RBXScriptConnection | OnPierceFunction)?
-- Fired when the cast pierces through something: cast, raycastResult, segmentVelocity, cosmeticBullet
Caster.CastFire: (RBXScriptConnection | OnCastFireFunction)?
-- Fired when a cast is initially launched: cast, origin, direction, velocity, behavior
Caster.CastTerminating: (RBXScriptConnection | OnCastTerminatingFunction)?
-- Fired just before a cast is destroyed: cast
-- State
Caster.AlreadyInit: boolean -- True after Init() has been called.
Caster.ObjectCacheEnabled: boolean -- Whether ObjectCache is currently active.
Caster.BulkMoveEnabled: boolean -- Whether BulkMoveTo is currently active.
-- References
Caster.WorldRoot: WorldRoot -- The WorldRoot this Caster simulates in.
Caster.FastCastEventsModule: ModuleScript -- The currently assigned FastCastEvents module.
Caster.ObjectCache: ObjectCache -- The ObjectCache instance (if enabled).
Caster.Dispatcher: Dispatcher -- Internal worker VM dispatcher.