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

Hi dev,
I have a little problem with the projectiles’s working.
In my game, I’m shooting a bullets and that reflects-off the walls and make corresponding angle and continue to move till maxDistance or maxTime.
Now what is wrong, when 1st time bullet collides with wall and gets reflected, then for the 2nd wall it sometimes clips-through that wall which is very odd. Bullet can’t ever pass through the wall even bullet’s and wall’s “CanCollide” are set to true and their “CollisionGroup” also has collision.

Here’s the reference:-
Video reference of issue

@Xan_TheDragon , can you please provide me the possible resolution in this case? Looking forward for response.

Thanks!

2 Likes

No cleaner method?
If i want to unequip the weapon, throw it away, what do i do with the caster? Will it aways be there?

2 Likes

I’ve been having the same question, I read the API and there’s only a “Terminate” method, but it doesn’t seem to work well for me. I think FastCast is kind of outdated at this point.

Well, using this was a massive waste of time. I don’t understand this, and for some reason it wasn’t mentioned that you need to be intermediate or so to understand how this works. All it accomplishes is making a stationary part, so… I’ll look for another gun module
image

my cosmetic bullet isnt showing up. is anyone else experiencing this issue?

Greetings,

I Am having a problem, The module is not working, It is probably because I did not know how to use it.

local Tool = script.Parent
local Remotes = Tool["Remotes."]
local Debris = game:GetService("Debris")
local FastCast = require(Tool.FastCastRedux)
local PartCahce = require(Tool.PartCache)

Remotes["Equipped."].OnServerEvent:Connect(function(Player)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	Character["Right Arm"]:FindFirstChild("RightGrip"):Destroy()
	local Joint = Instance.new("Motor6D")
	Joint.Name = "RightGrip"
	Joint.Parent = Character["Right Arm"]
	Joint.Part0 = Character["Right Arm"]
	Joint.Part1 = Tool.Handle
end)

Remotes["Unequipped."].OnServerEvent:Connect(function(Player)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	Character["Right Arm"]:FindFirstChild("RightGrip"):Destroy()
end)

local Caster = FastCast.new()

local Part = Tool["Gaurds fire particle"]
local PartProvider = PartCahce.new(Part, 100, Tool)

local RaycastParameters = RaycastParams.new()
RaycastParameters.FilterDescendantsInstances = {Tool.Parent}
RaycastParameters.FilterType = Enum.RaycastFilterType.Exclude

local CastBehavoiur = FastCast.newBehavior()
CastBehavoiur.RaycastParams = RaycastParameters
CastBehavoiur.MaxDistance = 200
CastBehavoiur.CosmeticBulletProvider = PartProvider
CastBehavoiur.CosmeticBulletContainer = Tool


Remotes["Activated."].OnServerEvent:Connect(function(Player, MousePosition: Vector3)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local Sound = Instance.new("Sound")
	Sound.SoundId = "rbxassetid://17299679453"
	Sound.Parent = Character.PrimaryPart
	Sound:Play()
	local Direction = (MousePosition - Tool["Wand build."].Part1.Attachment1.WorldPosition)
	
	Caster:Fire(Tool["Wand build."].Part1.Attachment1.WorldPosition, Direction, 100)
end)

Is there any way to slow down bullet midair, and then make it fast again, like time dilution effect?

Yes, the logic should be inside LengthChanged event.

how exactly do I do it, I cant really understand the script in the module.

all I need is to make the bullet slow down when a value is enabled, and vice versa the trajectory stays the same

nvm i divided the delta time to simulate the slowed speed, thanks for your pointer though :smile:

1 Like

I’ve been working with FastCast to create a gun system for a project I work on and have discovered after much frustration that ActiveCast.lua’s CloneCastParams method fails to clone the RaycastParams.RespectCanCollide flag properly, causing the ActiveCast’s RaycastParams to not exhibit expected behavior. Thankfully, it’s a really easy fix. You just need to add a line to copy that parameter over.

yo anyone here know how i can rotate my cosmeticpart? i want to have throwing knifes but they always face sideways from where im pointing

nvm figured it out, now how do i convert bullets to use models instead of parts?

This module is starting to get outdated, most of my gun systems with this module broke recently

do the hitbox in the client that starts the projectile, it’ll look like that other wise.

Hey, I can’t get the model for some reason.

That’s very weird; here is the direct download!
FastSphereCastRedux.rbxm (20.7 KB)

I have an error in the active cast script.
attempt to perform arithmetic (add) on Vector3 and number The error is on line 122.
When I tested it at first it worked perfectly fine.
After I edited a few of my scripts for the gun I’m making then I got the error.
I’m too smooth brained to find out what’s goin’ on and how to fix it.

Also, very nice work you’ve done here.

Hi, I have recently encountered a bug.
proof: https://gyazo.com/e78e9fc16d03b890a2793f5451e49987



^Walking in a straight line while the NPC is chasing me and shooting at it, you can see 2 bullets passed right through them twice, it happens more often in R6 than R15.

I am using the example gun.

Problem: When shooting a moving NPC the bullets lose its accuracy, as you can see in the gyazo clip I recorded, sometimes bullets pass right through the NPC as if they don’t exist, sometimes it gets so bad that every 2 bullets a bullet passes right through.

What I tried to do:

  • Tried setting Raycast params to RespectCanCollide to true.
  • Tried it with both R6 and R15, it happens in both.
  • Tried changing HighFidelityBehavior to Always and having the HighFidelitySegmentSize to numbers like 0.1 to 0.4 or even 1 to 10 lol.
  • Tried using the gun example with no modification (thinking it was a problem with how i tweaked the gun example to my liking) but no, even with the gun example it can be recreated with a simple moving NPC with Humanoid:MoveTo() and shooting at their torso.
  • Tried making the bullets bigger
  • Tried making bullets slower/faster
  • Tried recreating it in game not studio, still happens.

None of the above solutions worked so I gave up and came to here. I don’t know if this is a new bug or if this ever happened when I used it before but I only noticed now at least.

Note that this ONLY happens when I shoot at a MOVING NPC, I tried to recreate it while the NPC is sat still and it did NOT happen. It could be because of network/lag but at 10-100 ping and 240fps that shouldn’t be the case.

Would really appreciate any help, thanks for reading!

hi guys

im working on a baseball game rn, and i use FastCastRedux to handle pitch and hit balls cuz i know absolutely nothing about physics (I know, laugh at me :pensive:)
It works pretty good, I have no issue with it whatsoever. The BIGGEST issue i have with it is: I didn’t seem to set it up right, so as the game progresses the game lags more and more. I tried to pin it on the server, but rejoining during the lag seems to fix it, so that leads me to believe its an underlying issue with the client.

The video is of the issue I’m talking about (it usually happens whenever or when someone throws the ball).
Not included because I can’t find it anymore, but video 2 showed a player in the community lagging mid-pitch as soon as the ball was thrown and the lag wouldn’t stop until the cast terminated I believe (although the lag just happens randomly, mostly before a pitch is thrown)

The code snippets below are the ones that run on the client (please ignore how ugly and unorganized it is, im still learning how 2 script :pensive:)

Here is how I have it set up on the Ball Handler module (which handles ball visuals and partial fielding)

-- // Services \\ --
local PlayerService = game:GetService('Players')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local RunService = game:GetService('RunService')
local DebrisService = game:GetService('Debris')
local ServerScriptService = game:GetService('ServerScriptService')

-- // Variables \\ --
local FastCast = require(ReplicatedStorage.Carnavas.Modules.FastCastRedux)

FastCast.VisualizeCasts = false

local BallEvent = ReplicatedStorage.Carnavas.Events.BallEvent

local CountBindEvent = ReplicatedStorage.Carnavas.Events.CountBindEvent
local BallsFolder = game.Workspace:WaitForChild('Balls', 10)
local GloveSounds = ReplicatedStorage.Carnavas.Sounds.Glove

local Caster = FastCast.new()
local CasterBehavior = FastCast.newBehavior()

Caster.UserData = {}

local HitBall_MarkerCaster = FastCast.new()
local HitBall_MarkerCaster_Behavior = FastCast.newBehavior()

local module = {}

local SZ_Debounce = {false, 3}

LengthChanged function:

local function OnLengthChanged(ActiveCast, LastPoint, Dir, Length)
        local InitialBall = ActiveCast.UserData.InitialBall
        local HalfSize = ActiveCast.UserData.InitialBall.Size.Z / 2
        local Offset = CFrame.new(0, 0, -(Length - HalfSize))
        InitialBall.CFrame = CFrame.lookAt(LastPoint, LastPoint+Dir):ToWorldSpace(Offset)

        if Caster.UserData.LandingMarker then
            ActiveCast.UserData.LandingMarker = Caster.UserData.LandingMarker
            Caster.UserData.LandingMarker = nil
        end
        if ActiveCast.UserData.LandingMarker then
            local LandingMarkerInfo = ActiveCast.UserData.LandingMarker
            local LandingMarker = LandingMarkerInfo[1]
            local EndPosition = LandingMarkerInfo[2]

            if EndPosition and LandingMarker then
                local DistanceFromHitPosition = (LastPoint - EndPosition).Magnitude
                local FinalSize = math.clamp(ReplicatedStorage.Carnavas.Balls.Baseball.Size.X + 4 * (DistanceFromHitPosition / 25), 2, 28)
                LandingMarker.Size = Vector3.new(.75, FinalSize, FinalSize)
            end
        end
    end
    Caster.LengthChanged:Connect(OnLengthChanged)

CastTerminating function

-- CastTerminating function
local function OnCastTerminating(ActiveCast)
    local UserData = ActiveCast.UserData
    local InitialBall = UserData.InitialBall

    if UserData.LandingMarker then
        UserData.LandingMarker[1]:Destroy()
    end

    InitialBall:Destroy()
end

Video: Watch issue_demonstration | Streamable

I am extremely grateful for any help I receive (if I get any but im not really expecting any tbh) :pray:

1 Like

Soo i want to make a laser that can pierce, so i chose fastcast, the problem is that i need to get the full distance travelled as 1 number to set the laser’s size, basically what rayresult.Distance does, but here rayresult.Distance after RayHit gives numbers like 1.215 which is too small. How would i do that