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

I will be remaking the module (maybe, if time goes well).

This remake will contain cleaner (more readable) code, some slight bugfixes, and more intuitive documentation + usage, but for the record, I am ending my time on Roblox and moving on to new places, so my interest in maintaining this module has dwindled to basically nothing.

There are some glaring issues with v13 right now and so I will be fixing those first and foremost (i.e. how whitelisted casts don’t work properly) but once v14 is out, that’s probably gonna be it.

As far as lagging behind goes / replication issues, I probably won’t do much about those except maybe provide a template module or something to make the idea of a shared (client/server) caster easier to understand for newer programmers.

Edit: I’ll also look into realtime projectile control, but this is unlikely as it’s out of the scope of FC simulating real physics. It’d be better to add steering / homing projectiles in your own implementation, one of the drawbacks of making a common, easy-to-use module is that it can’t be specialized to certain use cases without hurting the average / normal use case.

14 Likes

Any tutorial on this? I just want a simple gun that shoots to point A to B, nothing fancy, unlike the pre-provided tool, which is super overwhelming.

Excellent news but sad to see you go. Good luck in your future endeavors!

1 Like

There is a memory leak with the gun example provided, caused by the PartCache module.
The Dispose function is never called, and so the bullets it creates in Workspace are never removed. They are re-created every time the player respawns.

People are copying this tool and adjusting some values to suit their needs. Right now this for sure is causing issues in people’s games and they have no idea.

I measured the memory usage by respawning my character every 0.5 seconds. The results:
Tool in ServerStorage: 5 min - 483 MB
Tool in StarterPack = 5 min - 672 MB
Another 10 min later - 1088 MB
Tool in StarterPack, PartCache removed = 5 min - 484 MB
Tool in StarterPack, PartCache fixed = 5 min - 470 MB

2 Likes

hey, how do i make penetration (piercing) i have no clue where to start off

RayHit does not seem to work on the client? It’s only working on the server.

So, I found an interesting bug and didn’t hesitate to report it.

I don’t know if it’s the way I scripted or the module itself, but every time I move and shoot, the gun does not target the crosshair and instead shoots in the direction away from the crosshair where I was moving.

The blue lines indicate client-sided raycasting, while the green ones are server-sided.

As you see, the client raycasts the target in my crosshair and tells the server to target where the client raycast hit. The server then raycasts to the exact target given by the client. But the problem here is that the module decided to raycast away from its intended target despite the client never telling the server to shoot there.

Captura de Pantalla 2022-12-12 a la(s) 12.24.00 p. m.

I tried searching for a solution, but I couldn’t find it. The module is fully updated, and the problem still persists.

I copied the example script and modified it to make my own gun system. I never changed the direction and Caster:Fire().

The server may have the exact same target however the position values of where to raycast from may be different due server to client replication.

Please post a repro file if you are reporting it as a bug.

The module doesnt implement remote events by itself and it works fine with the example gun given as a standalone.

Therefore its a you problem.

After doing some research, I realized that the raycast that is off from its intended target is a raycast from a client used for rendering visual effects.

Regarding the server-to-client replication, I found the problem and fixed it. Thanks for giving me an idea.

I’ve noticed that at very high bullet speeds (above 100), the cosmeticbullet appears to start considerably far away from the origin where its original position is set.

As you can see below, the bullet and trail start several studs away from the end of the gun, where I set the starting origin to be.

Is there any way to solve this and have the bullet and trail visibly start at the origin, instead of being many studs away?

Using an FPS unlocker might fix your issue. This is due to the bullet traveling faster than your FPS.

To potentially solve this in code, you need to wait one frame before moving the bullet.

1 Like

This looks like latency to me. If you are creating the projectiles on the server without any client sided visualization then the bullet is already moving by the time client receives the projectile, thus it appears as if the bullets are coming out of thin air.

Pros: Projectiles look much better specifically when moving.
Cons: The client may perceive as if they’ve hit a player when they in fact have not due to latency.

If you are already doing what I mentioned above then I am afraid there’s nothing else you can do about it.

1 Like

I see, so how do I do client-side visualization for bullets? I’m not sure where to start.

It is pretty simple, the players fire a bullet and you fire a cast, purely visual, then you fire the server which creates an invisible projectile for damage-dealing and then you fire the other clients with projectile information to render this bullet.

If you have a really big map and a lot of players and the other players are too far then you don’t even render the bullets at all.

A tip, keep gun information such as speed, bullet part etc… on a module script so you only have to send the gun type, the bullet hole and the direction to the client and so it stays more organized.

3 Likes

So, I could use a caster for the client to fire a purely cosmetic ray with no damage while having another caster to fire the ray for the server? (I’m making a singleplayer game, so I’m not particularly concerned about how the player looks like to others since there’s only 1 of them)

1 Like

If you’re making a single player game, you should make your gun work purely on the client and do nothing on the server.

Is there a way to make a fake origin? Like the hit-reg origin comes from the head but for cosmetic bullets it registers as if the origin is the head but it appears in the gun.

Edit: I figured it out, i casted a ray from the head to the mouse direction and if its hits i drift the direction of the bullet to what the head hit.

@Xan_TheDragon Would this ever be supported?

Yo how do I stop the cosmetic bullet from automatically deleting itself, I’m making a murder mystery game and I want the knife projectile to stay longer than like 1 second.

Never mind, it was because the knife was unanchored, new problem though, for some reason it works perfectly fine in studio but in game I get ‘attempt to index nil with raycast’.

Edit: I just replaced WorldRoot with workspace all good.