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

Best way to go about bullet refraction? What is the best way of doing this?

I’m fairly new to the whole client replication concept. How would I be able to do something like that for this module?

I make two bullets with the same parameters and fire them both on the server and client the server does the hit detection while the client is just for cosmetics

Can I ask a question? What happens when the “random direction”, or as i like to call it “spread” in fast cast is a negative value?

Im trying to make a FPS Game using FastCast (FC) and when the player shoots to make sure the server does not lag, we will fire it on the clients and do damage on server, FCH (Fast Cast Handler) is module btw

second line Dir = is the error

local directionalCFrame = CFrame.new(Vector3.new(), direction.LookVector)
local dir = (directionalCFrame * CFrame.fromOrientation(0, 0, Random:NextNumber(0, math.pi * 2)) * CFrame.fromOrientation(0, 0, 0)).LookVector

and here is the full function

function module.FireBullet(origin: Vector3, direction: CFrame, properties, isReplicated, repCharacter)


local rawOrigin	= origin
local rawDirection = direction

-- if the propertie aren't already required just require them
--[[
if type(properties) ~= "table" then 
	properties = require(properties)
end
--]]

local directionalCFrame = CFrame.new(Vector3.new(), direction.LookVector)
local dir = (directionalCFrame * CFrame.fromOrientation(0, 0, Random:NextNumber(0, math.pi * 2)) * CFrame.fromOrientation(0, 0, 0)).LookVector			

local bullet = script.Bullet:Clone()
bullet.CFrame = CFrame.new(origin, origin + direction)
bullet.Parent = workspace.Bullets
bullet.Size = Vector3.new(0.05, 0.05, properties.firing.velocity / 200)

-- useful with the server security i made, almost useless in this fps demo
local id = math.random(-100000,100000)
local idValue = Instance.new("NumberValue")
idValue.Name = "id"
idValue.Value = id
idValue.Parent = bullet

bullets[id] = {
	properties = properties;
	replicated = isReplicated;
}

-- if not replicated shooting then replicate
if not isReplicated then 
	--ReplicatedStorage.weaponRemotes.fire:FireServer(rawOrigin, rawDirection, id)
end

-- fire the caster
--Caster:FireWithBlacklist(origin, direction * properties.firing.range, properties.firing.velocity, customList, bullet, true,script.BulletGravity.Value)
CastBehavior.CosmeticBulletTemplate = bullet
local simBullet = Caster:Fire(origin, dir * properties.firing.range, properties.firing.velocity, CastBehavior)
simBullet.UserData["RepChar"] = repCharacter
simBullet.UserData["Camera"] = workspace.Camera
simBullet.UserData["Player"] = game.Players.LocalPlayer.Character

end

ReplicatedStorage.FCH:271: attempt to call a nil value

What do I do with the caster object when I no longer need it? If I just unrefence it will it automatically garbage collect?

That’s correct. It will GC like any other object, so granted you make sure you cut all references to it, it’ll go away.

1 Like

Can we get a ignore function if conditions are met cast will ignore hitpart and resume like normal?

Hi, is there any way to make the caster bounce off the floor? Thanks

You should consider reading the documentation (which is linked in the original post). It is covered there.

Yes. You will use a derived version of the pierce function. I believe the example gun has this implemented already, but basically you need to abuse how the pierce function works – the piece function is a means of telling FC to keep simulating a bullet and ignore whatever it just hit. It runs code (via OnRayPierced) that can do stuff when this happens. in this code, you will want to make use of ActiveCast:SetVelocity to redirect the bullet.

3 Likes

Hi, I’m currently implementing your module in my game (working great so far).
But I have a few questions:

  • I have seen some replies say a RemoteEvent is needed to replicate the projectile? They seem to replicate fine without one though?
  • Do I need a RemoteEvent for visual effects on hit? I want to create an explosion visual and am currently doing it inside of caster.RayHit. Would this be bad for the server?

I’m sorry if these questions have been asked before, but I didn’t have time to read the whole thread.

Hello, to answer your questions.

  1. What people are referring to is client replication, which is when the ray/bullet is visualized on clients only and not on the server. This is typically done to put less stress on the server as well as make the bullet feel like there is little to no delay. Remotes are required for this type of replication but client replication isn’t a must.
  2. If you are doing your cast on the server it should be fine, but maybe if there are going to be loads of these explosions at a time, you might want to replicate the explosion effect to the clients and not on the server.
1 Like

Ok, I LOVE this. For my game, I was using the weapons kit made by Roblox. However, when I wanted to make new weapons, I had a problem. Everything that made those weapons work was so complicated, it was hard to customize and understand some things. I noticed your module in the resources category and decided to check it out. It took literally 30 minutes to learn how to customize the module and modify it to fit my needs, and maybe 10 after that to completely reprogram one of the guns using it! I’m now going through my game and converting the weapons to use this. Thank you for this amazing module!

2 Likes

Hi! I have recently set up your module in my gun, a great module and works well! But I haven’t been able to figure out how to make it so that the debug value will change when you press a key, I have used user input service but the value won’t change, is there something I’m missing here?

Whenever using any of the signals, i get a “tables cannot be cyclic” error.
Using the version published on Jan 13, 2021 at 4:05:26 PM CST.
Disabled all beta features in studio and the issue still persists.
EDIT: found that this was an issue with me passing an ActiveCast as an argument to a remote.

Sorry if this is an obvious question, but how would I go about changing the velocity of a bullet after it penetrates a surface?

Use ActiveCast:SetVelocity(Vector3) in the RayPierced event. Check the docs for more info on what you can use, I’ve linked them in my OP. I’m on mobile right now so I can’t easily get the appropriate links.

1 Like

Hi, I wanted to ask how if it was possible to increase the size of the “hit box” of the ray cast for larger projectiles.

The only thing I can think of is that you need to change the value on the FastCast module itself (as in the direct return value from require(FC), not an instance created by FastCast.new()). The only reason I’d think it’s not working is because the FC static reference is copied into ActiveCast’s module, so it probably doesn’t propagate changes.

No it’s not. This is both the drawback and benefit of the system. The benefit is that testing collision on a line is super fast, but the drawback is that you can’t have width to your projectiles.

3 Likes

Can you use FastCast without an object?