Making a combat game with ranged weapons? FastCast may be the module for you!

Hey everybody!

Click to view key information for existing users
  • The module’s version is currently Ver 13.2.0 released on 12 November 2020** Changelogs can be viewed HERE
  • Support will only be given for the current version. Certain public toolkits that include FastCast may be using an out of date version. Please check the version in the main module (a comment near the top) before asking for help.

In this thread I’ll be showing off a module I made that may prove useful to you: FastCast (Click this to go to the page to get it). This module is really neat, because it uses raycasting (Commonly used for hitscan weapons, like lasers) in such a way that these raycasts can simulate bullet physics.

NEW! I’ve moved the API and tons of other helpful information over to my website! The link is at the bottom under the How do I use it? section.

So what makes this so important, how can it be a benefit?

Well, if you’ve ever tried making a ranged weapon here on Roblox, you may come across some rather irritating behavior with bullets while playing online. You may see things like bullet lag, jittering / “teleporting”, or even the Touched event of the bullet not firing. These issues can be very problematic to an FPS / TPS, and using hitscan isn’t particularly the best idea since that would require your gun to be modified to not use tracers. This can be harmful for things with slower projectiles, like rockets.

As a direct result of this problem not only being present in my own games, but also being present in other games, I had decided to put an end to relying on bullet physics. The final product of that goal is FastCast.

Click here to get a basic description of how it works, if you're interested in the technical side.

FastCast works by splitting up the line from start to goal into a ton of tiny pieces. These size of these splits is entirely based on velocity and distance. Each piece is used for its own individual raycast. Better yet, this script runs based on RunService’s Heartbeat event - Each heartbeat will make the next cast in line fire off. The result? Bullets that move extremely smoothly and consistently. The best part is that since I use Heartbeat, the bullet will accommodate for lag. In the event of any lag, the cast will move how much it should’ve moved as if there was no lag at all, ensuring that it stays on time and remains consistent to the motion values you specifed.

How do I use it?

Luckily for you, I’ve offered both a ready-to-run example script and full API documentation of my custom objects. You can check out the API (How to script with it, much like a Roblox wiki page) here: https://etithespir.it/FastCastAPIDocs/

Example Gun: FastCast: Redux Example Gun - Roblox

Feel free to reply or message me to give feedback. Hope it comes in handy!

1251 Likes
Basic bow and arrow
Some Assets for both Builders and Scripters
Game Development Resources [MEGA THREAD]
What causes projectile lag?
What math do I need to make physics based projectiles?
Bullet hit sparks
How do you keep gun fire delay minimal?
Gun System | Debris or Raycasting?
Combat Warriors Information
Is this Projectile System good or bad?
How do I make tank projectiles?
Firing Accurate Projectiles
Laser gun convert to FE [Reward]
How Do I Make A Throwable Knife?
[500+ USD!} Hiring 1 Scripter to join the team on our upcoming survival game!
Removing projectile delay from client to server?
How do I make a bullet raycast?
Reducing Lag with Large Number of Projectiles
Attempt to perform arithmetic on local 'Direction' value (a userdata value) help?
The First Person Element Of A First Person Shooter
Scripting Resources Mega List
How to make non-laggy guns
Problem with cannonball physics
Is using a Server Script for a GUI is fine?
[CLOSED] ImFarley - Programmer and Game Designer
Hit detection issues
Can someone introduce me to the different ways of moving a projectile?
Unique game concept - Looking for a scripter
How to create the smoothest projectiles possible?
Is there a more efficient way to make gun projectiles?
Upcoming Optimization to Collision Detection System - Beta Test on Mac Clients soon
Client-sided projectile, server-sided hit detection
SimpleCast - An Alternative to FastCast
Is my game Annihilation good?
Is there a better way checking when a projectile damages a player instead of using .Touched?
Bullet spread with BodyVelocity bullets?
Bullet velocity takes effect a few milliseconds after instantiation
Best Methods To Handle Arrow Projectiles
Referencing a object that exists on the client... in the server
OTS Gun System For SCP Game
What would the best way be to move gigantic amounts of bullets?
Alternatives to raycasting?
Part's position isn't staying updated
Project Resistance
Making projectiles more fluid?
Touched event not firing with anchored objects
Help with correcting a lazer system
Projectiles // RayCasting issues
Best Option for Bullet Hit Register
Best way to Smooth Ballistic Physics?
Are all Events Delayed?
Is here any projectile module?
Creating a simplistic gun system
Raycasting sanity server checks for ranged weapons
Is it possible for a ray to turn?
Boston Remastered: Credit List
The projectile is not being launched in the direction of the mouse correctly
How do you make a projectile go into the direction an object is facing?
How do I improve this shooting system?
Help with .Touched event
How do you make a projectile with physics?
What shooting is arsenal using?
How to create prograde and retrograde markers of a projectile?
Better way to make Bullets?
How would i get the hitposition and surface normal of a basepart when it collides with another basepart
Happy Holidays! Winter map
Best method for a bullet
How should I secure a damage RemoteEvent?
How do i make bullet travel using raycast?
PartCache, for all your quick part-creation needs
Server side hit detection
Help With Touched Event
Feedback on weapon system?
Is fast-cast worth it?
FastCast Per Gun?
Help with a gun script
.Touched Event not Firing when Supposed to?
Server side hit detection
Does any1 know what method they use for moving grenades in Phantom Forces?
Bullet script help
Need help with bullet hitboxes
Gun small script
How to approach bullet tracers? (Ex: Phantom Forces bullet tracers)
Server sided projectiles
Who should I set the network ownership of a projectile to?
Correctly Performing Spatial Queries
Projectile Motion
How do I create a bow and arrow? I already got the builds
Help! How would I do my damage on an attack that lerps or tweens on client?
Best way to make a projectile?
Third Person FE Gun Script
How to animate Tool Parts (Guns, Knifes etc.)
How to add the players character to this certain ignore list?
Projectile Motion
Help making projectile explosion with raycast
Client cast vs Raycast hitbox. Which is better?
How to make a part ricochet?
What module/system should I use for my gun?
Is there any explanation for this?
.Touched event only updating every so often with Fastcasting
Keeping track of ammo on server and client
Raycast resulting in weird and wacky results?
What would be a good way of making a cannon shell fire and drop off at certain time
Sword Smith | Script Swords in Just Minutes! [FREE]
Throwing knife method
How to prevent projectiles from pooling up at muzzle spawn point
TweenService breaking a OnTouch Event
Bullet Script Issue
How to whitelist parts with FastCast?
[CLOSED] VexTrexYT - Experienced Scripter
How can I offset this raycast in randomly?
Help with bullet spread
What is FastCast?
How do i loop through code at a certain speed?
Simulating wall penetration
Client Replication 101. The guide to replicating effects to clients
How I Can Fix Turret Bullet [Not Solved]
FPS Game Idea! - Name Needed and Feedback!
Third Person Gun Help
Blackout Credits
How would i add bullet drop to this Ray?
How can we determine where an object we move will go beforehand?
Is it possible to pre-calculate the destination of an object?
How to make a projectile client side detection
Ending a ray with FastCast?
How do i raycast effectively?
Designing an FPS Framework: Beginner's guide
How do i make a curve using velocity?
About hitbox problems
Change FastCast's projectile acceleration to achieve parabolic trajectory
How to make good projectiles
I'm making a grenade launcher and I don't know how to calculate the trajectory
How to make a gun
Projectiles Spawning Incorrectly
Raycast Laser beam laggy
How would I go about calculating a bullet's Trajectory?
Best way to move a part and it doesn't look laggy/glitchy
Issue with gun bullet direction
How can I make a client-sided projectile?
Feed back on Plants vs Zombi games!
Raycast Simulation (Projectiles without a part)
Best way to shoot a projectile?
Why is my script not working?
Help making a Danmaku/Bullet Hell pattern
Server Side bullet shooting
Auto gun not stopping
Tool doesn't work properly
How to make a grenade system?(help)
What gun system should I use?
How to make raycasting hitboxes
Mochi Skills - One Piece Fruit - Open-Source [UPDATED, 2 SKILLS NOW]
Cloning a model with server scripts from LocalScript?
Need help "replicating" velocity using raycast
Writing an FPS framework (2020)
Writing an FPS framework, part 2 (2020)
The best way for bullet hitreg
FastCast terminate cast
FastCast, Separating Server and Client Functions
Why won't the part damage npc/players?
Bullet trail/tracer effect help?
Help with making bow
How would I kill something with a part I created?
How should I go about hit detecting bezier curves?
Gun System tutorial?
I made a custom gun script!
How would I go about turning this functioning gun into full auto with spread?
Bullet doesn't damage NPC when too close
Bullet doesn't damage NPC when too close
Couple questions about free model guns. And question about R6/R15 humanoids
Alternative to .Touched for fast and responsive stickiness
Best way to make bullets for guns/detect shots
Bullet Dropping when at low speeds. Trying to find a way to make bullet unaffected by gravity
What should I use to make the Bullet of the weapon shot
Decal facing the right way
How do I smooth out the movement of new parts on the client?
Doom Towers: Credits & Attributions
STREET FIGHTER | Update Log
Projectile and client prediction
Extremely imperformant tracer visualisation
Alternative to hit detection, but
Realistic Gun System
How to make a repeat until stop when it touches something?
Fastcast, how should i use fastcast to deal damage to a humanoid on the server from the client
[OPEN] Capt_George // Programming // Terrain // Graphics
How would I approach making bullet drop guns?
How do I verify from server that an ability/skill is possible to happen efficiently?
Teach me about gun raycast
Moving a part using tweenservice, runservice or body movers?
How to get the thickness of a Part
FastCast - Projectile-to-Projectile Collisions
Making my throwing system less janky
Help with Arrow physics and arch
Ball Throw Support
Making Part Rotate With FastCast CosmeticBullet
Physical bullet not spawning correctly
Handling Projectile Movement
How to make A projectile Smooth like this
Is there a way to make Fast Cast : Redux a bezier curve?
Studio performance when opening/playing games is much worse
Studio performance when opening/playing games is much worse
Projectile path for throwing objects?
ClientCast - A Client-based, Idiosyncratic Hitbox System!
I M P A S S E - Credits Board
Issue with Raycast, "attempt to index nil with 'Instance'"
Lapiz: A simple gun system [V1.1]
Need a Simple Gun System
How do I slow a raycast down?
How Can i Make A Ability
Network Efficient and Safe Practices with Projectiles
Network Efficient and Safe Practices with Projectiles
Raycast Projectile Bug When Changed In Speed [FastCast Redux Module]
Effective way to make a weapon?
Alternatives to using .Touched for hit detection?
Ball is Curving incorrectly
Projectile Gun - How To..?
Throwable Projectiles - Recommendations appreciated
What's a good way of replacing .Touched()?
Blood Engine - A droplet emitter system
Anchoring a projectile when touched
I really need help fixing this problem
How to make a gun
How can I make a bullet system?
Shoot projectile on client/ server does not work well
Best way to make non-instant projectiles
What is better to make projectile skills?
Projectile/bullet delay
Whats a good Hitbox System for projectiles?
FastCast. Can anyone explain how to use it?
How to make perfect hitbox
FastCast Laggy With Projectile Models
Blood Engine - A droplet emitter system
Accurate Projectile?
Best way to do accurate hit detection with CFramed projectiles?
:ApplyImpulse() isn't smooth
Create a Snowball
Problem with barrel that should explode with a bullet
Need help clarifying some things
How to detect infinite distances with tween?
A way to improve projectile sanity
What do you need to know to make a weapon?
Whats better? BodyVelocity or Tweening
Server get lags, but don't have their in studio
Revolution Documentation
Game organization
Let's talk projectiles?
How to create ray from vector3 and angle?
Help with Projectile direction problem
[HIRING] Weapons Coder (Rocket Launchers + Grenades) [OPEN]
Anyone know a good way to make a controllable turret?
Bullet Damage Detection
On the Matter of Lag Compensation & RayCasting
How can I make my gun system not lag?
How would I Script Spread and Drop?
Projectile Spawn Latency/Delay
The First Person Element Of A First Person Shooter
What is a delay-free method to detect collisions on projectiles?
Problem with projectiles
How do I make a Rocket
How to access Events stored in Tool at all times?
How to fix my wait trouble?
How to make detached raycast bullets
How do u throw a sword w/ FastCast module?
What's the best way to network a projectile knockback system?
How do I make collisions with fast moving bullets?
Most Efficient and Performance wise method for Cube-like Hitboxes?
Projectile freezes midair sometimes
How would i put a bullet in the right direction?
New RaycastParams Property, Deprecating Old Raycast Functions
Best way to do physics based bullets instead of ray-casted?
Spell casting system
I can't see my gun's bullets anymore
How can I use my RayCast with velocity?
How could i make bullet drop?
Projectiles and collision. What do you feel should happen in the following scenario?
Been trying to figure out how to do bullet drop with ray-casting for a while now, need some help
Problems with my guns on my star ships
Request for bullet drop formulas
What are you working on currently? (2020)
How do I make a gun?
Handling Railgun Bullets
How do you guys do tracer rounds for bullets?
Make spear tween to mouse position?
Projectile hit detection
Need help with gun
Can someone help me create ray related bullet drop
Best Option for Bullet Hit Register
Moving a part with WASD

Didn’t you already…

Is this a dedicated expansion thread or something?

60 Likes

Will this work if i want to make a bow and arrow or just a gun

33 Likes

Oh! Yeah. I’ll edit that thread. It was suggested that I create a dedicated thread due to the level of completion this module had. Thanks for reminding me.

41 Likes

This will work for anything - I used a gun as an example because it’s the most common thing that would need this module.

Any sort of projectile will work even if it’s not for a weapon. In your case, you’ll want to fire the caster with a bit of a slower velocity so that it travels more like an arrow would.

28 Likes

If this has latency compensation ala Mad Murderer’s (firing client draws projectile immediately, other clients begin drawing projectile when and where the projectile should be at that moment) that would be so cool

26 Likes

It certainly does include lag compensation!

In the event of any lag, heartbeat’s delay time will be over the expected 1/60th of a second. The length of each ray is calculated through a specific equation:

RayLength = NormalizedDirection * Velocity * DeltaTime * 2

For clarity just to anyone who may end up being unsure, NormalizedDirection is a unit vector storing the direction of the ray, Velocity is the value specified by the user when the :Fire() method is called, and DeltaTime is the amount of time that the latest heartbeat took. So if lag occurs, the ray’s length will be made longer to compensate without issues.

37 Likes

Something I have been struggling with for so long is ranged weapons, and now this appears! Glad someone asked the Bow and Arrow question as that would likely be my intended use. Will this be able to create curved trajectories, such that if a player shot an arrow straight up 90 degrees, it would eventually fall back down in the same/near location it left?

34 Likes

Curved trajectories are still on the to-do list.

I don’t think appending the feature would be too much work.

I’ve narrowed down my plans to a pretty direct idea. For the next version I’m going to be appending a Gravity property. I’ll formally document it when I release the change, but a general explanation is as follows:

The Gravity property will be part of an individual caster object. Its default value will be 0 meaning that the trajectory is not affected by gravity. Users can set this value to whatever they please. I’ve been considering whether or not to add a method that sets the Gravity variable to be equal to the Workspace’s Gravity Property. I think it would be more common practice to just run Caster.Gravity = workspace.Gravity when a user creates the object, though.

This change would require a few edits to the script that runs each ray, especially the LengthChanged event. Right now, that event gives the start of the entire ray and the distance to the current ray point from that start value as some of its arguments, which would not be correct in terms of rotating the projectile based on flight path. I’d have to change it to be per-segment. This ideally won’t cause too many issues with migrating over from the previous version when this releases.

Given that I see a lot of the usage relates to arrows, I’ve also considered appending a second value - a Vector3, specifically - so that you can simulate wind and other factors. This value would represent a force and be added on top of the gravity value so that you can have a specific spot for gravity and a specific spot for this extra force. This feature will also benefit things like long-range weapons (sniper rifles, for instance) as they are affected by wind to a very notable extent.

Edit to blow this question out of the way: This Vector3 value will be in world space. That way, it’s easier to have a global wind value distributed to every caster. I might end up adding a way to make it behave in object space, but I don’t want to over-complicate things. Of course, as mentioned, this is all still up in the air.

When I release version 3, I’ll include documentation on these just as I did every other property.

35 Likes

I was asking about latency though, the time it takes for packets to travel, not framerate.

25 Likes

Oh. In that case, no, I have no compensation for this. I could add that later down the line probably by letting the server-side send a tick() value through some remote call (of course, clients may have different values for their epoch, so for the sake of simplicity I’ll ignore that here), and then allow that time value to be passed into the caster as a sort of thing to say “Hey, bump it ahead this much”. That’s just an idea.

For now and in the next version, I don’t plan on adding this feature, but that’s still up in the air. I’ll definitely consider it though.

20 Likes

we need more people like you in the world :slight_smile:

56 Likes

If you click on terrain then the bullet fires in the opposite direction, please fix this, I need it ASAP.

9 Likes

Are you sure you’re using the script correctly? This sounds like it may be an issue in your hit detection code, as the Caster:Fire(...) method takes in a Vector3 origin value, a Vector3 direction value (multiplied by the maximum distance for the current ray), and the speed of the bullet.

You will want to validate your code that determines the location or direction of the hit. Feel free to messsage me if you’d like more directed help.

12 Likes

Hey everybody! I’ve just released Version 4 of the module. Please make sure to message me if you see anything wrong.

This version adds…

Physics!

(I’m mentioning @SmoothBlockModel and @CheetahSp33d since you two had asked about it.)

I’ve also created an update log in the bulletin board. Please read it, as I’ve moved the API docs over to my GitHub as well as some other important information: FastCast Changelog Thread

56 Likes

Excellent for a bow and arrow

27 Likes

I’m not sure I completely understand. My game has a BUNCH of projectiles (absolutely zero hitscan weapons) ranging in size and speed. From what I read, this seems to be very useful to me, but I don’t want to go through the effort of getting and reading your model (not on my computer). What exactly does this do?

15 Likes

In basic, this module supplies an API that allows you to use raycasting that simulates physics for bullets. I think the easiest example would be to give you a rather brief script, since my original post explains it already. In the case that this kind of explanation isn’t what you wanted, just let me know and I’ll fix it up.

If you look at reply #15 I have a picture of a ray firing off with physics. Each one of those black cones is a segment. This module basically splits up the path of a bullet into tiny segments whose length is based on the speed of the projectile and how long the latest Heartbeat took (which allows it to accommodate for lag). Each of these segments is an individual hitscan test over a short range. They are fired off sequentially based on velocity and time. One of the immediate concerns I may see is that extremely fast bullets have long rays, but the frame-rate Roblox is limited at will make it not perceivable by players, so it works pretty well even with extremely fast bullets.

Let’s say you have a sniper rifle, something with a very high-speed projectile. You’d start off with a script a little something like what follows to handle the rifle’s function.

The script is lengthy (not overkill) so I’m going to wrap it into a details section. I’ve written functions that explain what each part is doing via comments so hopefully it should clarify a lot of stuff.

I forgot to append my API to the original post, as I did do documentation for this system. Sorry about that. You can have a look at it here: https://github.com/XanTheDragon/FastCastAPIDocs/wiki

Click to view
local FastCastModule = require(wherever the module is)
local SniperCaster = FastCastModule.new()
SniperCaster.Gravity = 5 --Add a slight bullet drop at 5 studs/sec^2 (game gravity is 196.2 by default)
SniperCaster.ExtraForce = Vector3.new() --You can set this to apply wind so that you can offset the bullet

function RayChanged(Origin, SegmentStart, Direction, Length)
    --As mentioned in the API, this function will fire every heartbeat, or when a new ray segment is calculated.
    --Origin is the start of the ray, where the muzzle is. SegmentStart is the start of the current segment.
    --Likewise, direction and length are the direction + length of the current segment.
    --Each one of the black cones in the image I referred you to is a segment.
    
    --In this function, you might update a tracer part by setting its CFrame or update anything else that may appear visually based on the bullet.
    --You can also use this function for something like playing a bullet near-miss sound!
end

function OnHit(Part, Position, Normal, Material)
    --This function will run when the ray hits something. The parameters returned are self-explanatory, but for the sake of good practice I'll explain anyway
    --Part is the part that got hit (will be nil if the ray reaches the end of its distance.)
    --Position is the position of either the hit or the point of the ray when it ends.
    --Normal is the surface normal of the part hit (this will be a zero-vector if Part is nil)
    --Material is the material of the part hit (this will be Enum.Material.Air if Part is nil)
    
    --Here, you might damage the player that got hit or do anything else involving when the bullet hits something.
end

--Now that you've set up the way the caster should work, you can connect its events to the two functions above.
SniperCaster.LengthChanged:Connect(RayChanged)
SniperCaster.RayHit:Connect(OnHit)

--After the setup of the caster is done as shown above, you can use this to fire your gun:
local BulletSpeed = 1600
local MaximumDistance = 1000

function FireWeapon(MuzzleEndPosition, FireDirection)
    --Some arbitrary function that will fire the gun. This might be paired to something in a Tool's Activated event.
    SniperCaster:Fire(MuzzleEndPosition, FireDirection * MaximumDistance, BulletSpeed)
end
23 Likes

How does the segmented raycasting over time combat the edge case of being able to tunnel into an object that is moving towards the projectile?

17 Likes

All my projectiles are relatively slow and easy enough to dodge when you see it coming, I’m assuming this is not for me?

8 Likes