-
Notifications
You must be signed in to change notification settings - Fork 3
API V2 Reference: Caster
This is obsolete. Visit https://etithespirit.github.io/FastCastAPIDocs/ instead.
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.
WorldRoot WorldRoot
The target WorldRoot that this Caster runs in by default. Its default value is workspace
.
ActiveCast Fire(Vector3 origin, Variant<Vector3, number> velocity, Vector3 acceleration, Vector3 directionWithMagnitude, Instance cosmeticBulletObject, RaycastParams raycastParams, Func<boolean, ActiveCast, RaycastResult, Vector3> canPierceFunction)
⚠️ Ensure your pierce function is as efficient as possible! If it takes longer than a single tick to finish running, FastCast will throw an error.
Fires a ray from this Caster. This actively simulated ray ("bullet") is represented as an object referred to as an ActiveCast. The velocity parameter can either be a number or a Vector3. If it is a number, it will be in the same direction as directionWithMagnitude
. Acceleration determines a constant force that is applied to the bullet as it flies. directionWithMagnitude
represents the direction the bullet will travel (if velocity
was a number) as well as the maximum distance it can travel.
Most importantly, canPierceFunction
is a function that takes in the following arguments:
- Its argument types are: ActiveCast, RaycastResult, Vector3
- It must return a boolean (true or false).
This first parameter is a reference to the ActiveCast that fired the function, since this function may be used across many different instances. The second parameter is the result of the latest ray hit that should be checked, and the final parameter is the velocity of the projectile at the time it hit.
ActiveCast, Vector3, Vector3, number, Vector3, BasePart LengthChanged
In order, the parameters are named: casterThatFired, lastPoint, rayDir, displacement, segmentVelocity, cosmeticBulletObject
This event fires every time any ray fired by this Caster updates and moves. The lastPoint parameter is point the ray was at before it was moved. rayDir represents the direction of movement, and displacement represents how far it moved in that direction. To calculate the current point, use lastPoint + (rayDir * displacement). segmentVelocity represents the velocity of the bullet at the time this event fired. cosmeticBulletObject is a reference to the cosmetic bullet passed into the Fire method (or nil if no such object was passed in)
ActiveCast, RaycastResult, Vector3, Instance RayHit
This event fires when any ray fired by this Caster runs into something and is terminated. The first parameter references the ActiveCast that fired this event. The returned RaycastResult is the result of the ray that caused this hit to occur. segmentVelocity is the velocity of the bullet at the time of the hit, and cosmeticBulletObject is a reference to the passed in cosmetic bullet. This will not fire if the ray hits nothing and instead reaches its maximum distance.
ActiveCast, RaycastResult, Vector3, Instance RayPierced
This functions absolutely identically to RayHit with the exception that it instead fires when the ray pierces something. This will never fire if canPierceFunction is nil.
ActiveCast CastTerminating
This event fires while a ray is terminating (so after RayHit has fired, if applicable, but before all of the data in the ActiveCast is disposed of, which means that it is still safe to access cast information in this event.)
This will always fire after RayHit, if the ray hits something. If the ray reaches its maximum distance without hitting anything, then only this event will fire.