API Reference: Caster - EtiTheSpirit/FastCastAPIDocs GitHub Wiki
This is obsolete. Visit https://etithespirit.github.io/FastCastAPIDocs/ instead.
Caster
A caster is an object that represents a type of ranged weapon (or whatever the module is representing). It provides a means of firing projectiles as well as keeping track of these projectiles. It is analogous to a gun or other firing mechanism.
Methods
void Fire (Vector3 origin, Vector3 directionWithMagnitude, Variant<Vector3, number> velocity, [BasePart cosmeticBulletObject = nil], [Instance ignoreDescendantsInstance = nil], [boolean ignoreWater = false], [Vector3 bulletAcceleration = Vector3.new()], [Function<boolean, BasePart, Vector3, Vector3, Material, Vector3> canPierceFunction = nil])
The primary projectile firing function. This has a lot of information to take in. The necessary parameters are the first three:
- origin represents the origin of the projectile, or where it starts.
- directionWithMagnitude represents the direction the projectile will be flying in. The magnitude of this vector should be the maximum distance this bullet is allowed to fly. This is similar to a raycast in that the cast can not travel further than the magnitude of this ray. If the cast exceeds this distance,
RayHitwill fire with all null arguments (with the exception of itshitPointparameter, which will be the end location of the bullet, and thematerialparameter which will beEnum.Material.Air) - velocity represents the movement of the projectile. It can either be a number or a Vector3. If it is a number, it means to move in the same direction as directionWithMagnitude at the given speed. If it is a Vector3, the velocity of the projectile is set in world space.
This function also takes in several other pieces of information:
- cosmeticBulletObject is an optional parameter that is basically an object to keep track of. This object is passed into the LengthChanged event. Hence the name of the variable, this is intended to be a part that is CFramed to grant a visual representation of the projectile.
- ignoreDescendantsInstance is handled identically to rays in Roblox, where any BaseParts that are descendants of this object are ignored by the ray.
- ignoreWater will cause the projectile to ignore terrain water and pass through it without registering a hit.
Finally, the function takes in two extra values:
- bulletAcceleration defines a force that is applied to the individual bullet.
- canPierceFunction is a function that returns a boolean and takes in BasePart, Vector3, Vector3, Material, Vector3 as its arguments. This function is called whenever the ray hits something (the four arguments being identical to the arguments that
RayHitis fired with, minus the cosmetic bullet). It should return true if the bullet should ignore this hit and pierce the object, and false if the bullet should stop and register a hit. Please note that this function may be intensive and cause excessive load to the server or clients.
void FireWithWhitelist (Vector3 origin, Vector3 directionWithMagnitude, Variant<Vector3, number> velocity, table whitelist, [BasePart cosmeticBulletObject = nil], [boolean ignoreWater = false], [Vector3 bulletAcceleration = Vector3.new()], [Function<boolean, BasePart, Vector3, Vector3, Material> canPierceFunction = nil])
Identical to the stock Fire method just above, with the addition of the whitelist parameter and the removal of the ignoreDescendantsInstance parameter. When this method is used, only BaseParts that are in the whitelist will be able to stop the ray and cause it to fire RayHit. All other parts are ignored. It otherwise functions identically to Fire, so use that as a reference for what the parameters mean.
If you need to conditionally ignore certain parts, consider using canPierceFunction.
void FireWithBlacklist (Vector3 origin, Vector3 directionWithMagnitude, Variant<Vector3, number> velocity, table blacklist, [BasePart cosmeticBulletObject = nil], [boolean ignoreWater = false], [Vector3 bulletAcceleration = Vector3.new()], [Function<boolean, BasePart, Vector3, Vector3, Material> canPierceFunction = nil])
Identical to FireWithWhitelist, but it uses a blacklist instead of a whitelist. When this method is used, BaseParts that are in the blacklist will be ignored by this ray under all conditions. All other parts are factored in. It otherwise functions identically to Fire, so use that as a reference for what the parameters mean.
If you need to conditionally ignore certain parts, consider using canPierceFunction.
Events
Vector3, Vector3, Vector3, number, Vector3 BasePart LengthChanged
In order, the five parameters are named: origin, lastPoint, rayDir, displacement, segmentVelocity, cosmeticBulletObject
This event fires whenever the caster updates the ray and moves it forward. The origin parameter is the origin of the entire cast (or where the ray started when it first fired). lastPoint is the previous location of the ray before it moved (and fired this event). rayDir is the direction in which the ray moved, and displacement is how far it moved in that direction. The segmentVelocity parameter is the velocity of the ray segment that triggered the event (note: this is relative to the start of the segment). Finally, cosmeticBulletObject is identical to the object passed into the Fire method you used (Fire, FireWithWhitelist, or FireWithBlacklist)
BasePart, Vector3, Vector3, Material, Vector3, BasePart RayHit
In order, the five parameters are named: hit, point, normal, material, segmentVelocity, cosmeticBulletObject
This event fires whenever the ray runs into something that stops the ray (so if you define canPierceFunction and it returns true for a given part (allowing the ray to pierce), this event will not fire). The hit parameter is the BasePart that was hit by the ray, or nil if the ray didn't hit anything and instead hit its maximum distance. The point parameter is the location where the ray stopped, for instance, where it hit the wall or where it ended after travelling its maximum distance. The normal parameter is the Z-relative normal of the surface it hit -- It is a vector whose direction is identical to the direction of the surface the bullet ran into. This can be used to orient things like hit decals for impact marks. The material parameter is the material of the hit part or terrain voxel. This will be Enum.Material.Air if hit is nil. The segmentVelocity parameter is the velocity of the ray segment that triggered the hit (note: this is at the start of the segment, not at where it hit). Finally, cosmeticBulletObject is identical to the object passed into the Fire method you used (Fire, FireWithWhitelist, or FireWithBlacklist)