Skip to content

Caster

What is Caster?

This page describes what the Caster


How to get Caster

To get Caster, you first need to require the module:

local HomingCast = require(.../HomingCast)

Then, create the Caster:

local Caster = HomingCast.new()

Remember!

The Caster must be created only once, as it serves as the base for all casts


What is Caster?

Caster is used to start the simulation of a cast

Caster:Fire(StartPosition: Vector3, StartDirection: Vector3, Speed: number | Vector3, Target: Model | BasePart | Vector3, Properties, PhysicsProperties?)

How to get Properties?

To get Properties, use:

local Properties: {} = HomingCast.NewProperties()

Read more about Properties.

The Caster:Fire function returns an InfoCast

Beware

If you use physics simulation, speed parameter will become not a constant speed, but an impulse

If Speed parameter is number then impluse will be applied in StartDirection


Caster contains 5 signals

PositionChanged

PositionChanged(InfoCast, Position: Vector3, Direction: Vector3, Distance: number, Target: Vector3 | BasePart, CosmeticBullet: BasePart?, UserData: {})

This signal fires every time the Caster moves

Useful Tip!

If you want your projectile to follow the path and align with the flight direction, use this code:

Caster.PositionChanged:Connect(function(...) 
    if CosmeticBullet then
        local BulletSize = CosmeticBullet.Size.Z / 2
        local Offset = CFrame.new(0, 0, -(Distance - BulletSize))
        CosmeticBullet.CFrame = CFrame.lookAt(Position, Position + Direction):ToWorldSpace(Offset)
    end
end)

RayHit

RayHit(InfoCast, RayCastResult: RaycastResult, Direction: Vector3, CosmeticBullet: BasePart?, UserData: {})

This signal fires when the Caster hits something


Terminated

Terminated(InfoCast, Reason: string, CosmeticBullet: BasePart?, UserData: {})

This signal fires when the Caster terminates due to exceeding the maximum flight distance, exceeding maximum flight time, or being manually terminated

What is Reason?

The Reason parameter indicates why the cast was terminated. Possible values:

  • Self - The cast was terminated manually
  • MaxDistance - The cast exceeded the maximum flight distance
  • MaxFlyTime - The cast exceeded the maximum flight time

TargetLost

TargetLost(InfoCast, LostTarget: Vector3 | BasePart, Position: Vector3, Direction: Vector3, CosmeticBullet: BasePart?, UserData: {})

This signal fires when the Caster loses its target


CheckpointReached

CheckpointReached(InfoCast, CheckpointName: string, Position: Vector3, Direction: Vector3, CosmeticBulletTemplate: BasePart, UserData: {})

This signal fires when the Caster reaches a point in the trajectory

Custom Trajectory

More information about Custom Trajectories.