FastCastRayInfo is a type storing basic information needed for FastCast's simulations.
This is a template object. Changing any stored values will not change the behavior of any casts that are simulating when the change is made - it is simply used to set up new ActiveCast instances.
It is advised that you create this object once and then reference it every time you need to call Fire. This is not required, but it is advised if possible.
In any cases where you need to edit a property of this object, do that instead of creating a whole new FastCastBehavior.
RaycastParams? RaycastParams [ = nil ]
The RaycastParams that apply to all casts fired from this Caster. When the Fire method is called, this
RaycastParams is duplicated, and as a result, changing the parameters of this template object will do nothing to existing ActiveCasts.
number MaxDistance [ = 1000 ]
The maximum distance that this cast can travel. If the cast continues travelling without hitting any parts, and the distance it has traveled in total exceeds this value, then the cast will be automatically terminated, firing the
CastTerminated event (see Caster). A good target value for general games is the longest distance achievable in your game's map (e.g. one corner of the map to the opposite corner).
Vector3 Acceleration [ = Vector3.new() ]
The constant force applied to this cast. This is good for things like gravity that affects projectiles, or a constant force of wind.
Critical Performance Warning!
Do not set this value to incredibly small units! This may cause severe performance problems.
HighFidelityBehavior = Always, be wary of exponential cast lag. This is an issue caused when the ray has to split into so many segments that it causes lag, which makes the next frame longer, which means that the next cast has to break into more segments (because its ray is longer), which means even more lag, which means the next frame is even longer, and so on. If the system encounters this type of lag, it will automatically throw an error and terminate the cast, as the lag is often bad enough to cause the game to stop responding.
This value may not be exact when used!
FastCast will attempt to split segments into pieces of this size, however this may not always be possible as this value may not evenly divide into the length of the given segment.
If this value does not divide evenly into the length of the cast segment, then the module will count how many segments it was able to make (excluding the leftover / remainder), and then upscale the existing whole slices to be slightly longer so that they fill the entire space of the segment evenly.
HighFidelityBehavior is not
Default, then the size of raycast segments is enforced to be as close to this value as possible where applicable (see
HighFidelityBehavior for more). Instead of creating a cast with a length based on the amount of time that it took to calculate and using that value itself, it will instead split that value into pieces that are this many units long. This can be used to ensure hit detection accuracy for physics simulations. This is useless for non-physics casts, and will not do anything if the cast's acceleration is a zero vector.
This is comparable to an Enum -- Limited range!
The only legal values here are
3. Attempting to use a value outside of this range will throw an error.
FastCast's base module includes a
HighFidelityBehavior index that works sort of like an enum. It's probably better to reference this index instead, such as via typing
FastCast.HighFidelityBehavior.Default instead of typing
The method in which FastCast handles physics cast accuracy. This is useless for non-physics casts, and will not do anything if the cast's acceleration is a zero vector.
- Default - FastCast will behave as it normally does, and use a segment length based on delta time.
- [NOT IMPLEMENTED] OnlyWhenHit - Similar to Default, but if a segment registers a hit, it will recalculate that hit to see if it really should have hit..
- Always - FastCast will always enforce that the segment length is as close to
HighFidelitySegmentSizeno matter what. Be careful to not cause exponential cast lag (see
Overridden by CosmeticBulletProvider!
CosmeticBulletProvider has been defined then this object will be ignored in favor of using the provider. If this is still defined while a
CosmeticBulletProvider exists, a warning will be logged and this will be set to nil.
A template for your cosmetic bullet, if desired. Every time the Fire method is called, this template will be duplicated and parented to
CosmeticBulletContainer. It will then be passed into the
LengthChanged event so that it can be CFramed or updated in whatever manner is desired to visually display the cast.
Overridden by CosmeticBulletProvider!
CosmeticBulletProvider has been defined then this object will be ignored, and the parent of the cosmetic bullet will instead be set to the container object for the PartCache instance.
A predefined container object that all cosmetic bullets will automatically be parented to when automatically created in the Fire function. Generally, a good place is a new Folder or Model created in the Workspace, but any location in the Workspace will work.
External Library Required
This component relies on code that is not included with FastCast!
To use this component, you must have PartCache.
This replaces CosmeticBulletTemplate!
This is intended to be a replacement to
CosmeticBulletTemplate is defined and this is defined as well, a warning will be logged and
CosmeticBulletTemplate will be set to nil.
An alternative to
CosmeticBulletTemplate that, rather than having FastCast clone the part when its created, provides a
PartCache instance that FastCast can use to acquire new cosmetic bullet instances. This is important for performance in large-scale games with lots of bullets going around, and should be used in favor of
CosmeticBulletTemplate for large games.
boolean AutoIgnoreContainer [ = true ]
If true, and if your
RaycastParams is using a Blacklist, the
CosmeticBulletContainer instance will be appended to the blacklist if it is not there already. It will be appended when the Fire method is called. This will not function if it is using a Whitelist.
Func<boolean, ActiveCast, RaycastResult, Vector3>? CanPierceFunction
Pierce Performance Warning
Ensure your pierce function is as fast as possible! The caster yields until the function returns so that it can determine what to do with a hit. If the function takes longer than a single tick to return, FastCast will throw an error.
A function that is called by FastCast whenever a ray hits something. It should return true if the ray is allowed to pierce the object (which will cause FastCast to continue simulating and fire the
RayPierced event), and false if the ray should terminate (firing the
The first parameter is a reference to the ActiveCast that called this function. The second parameter is the RaycastResult that was acquired before calling this function. The third parameter is a Vector3 representing the velocity of the ray at the time that it hit (this is good for velocity-based piercing).
An implementation of this function might look like this:
function CanRayPierce(cast, result, segmentVelocity) -- Let's pretend my projectile is a laser. if result.Instance.Transparency >= 0.5 then -- This part is at least 50% transparent. -- My laser can pass through these parts. return true end -- It's less than 50% transparent. My laser can not go through these parts. return false end