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

.new() isnt working for some reason, can i have help?

  1. Modify the RaycastParams that you pass in.
  2. You can (and should) use a second caster if its behavior is different than the primary weapon.

I think you’re approaching the problem incorrectly. Your message is a bit confusing though, I’m not sure of your intent. OnServerEvent should only be doing things like firing the caster. The events should be connected to externally.

If you want to track which player fired what bullet, use ActiveCast.UserData:

remote.OnServerEvent:Connect(function (player, ...)
    local cast = caster:Fire(...)
    cast.UserData.Creator = player
end)

Edit: Got ninja’d by #741. He has the link there.


Once you are more specific, yeah. Which .new()? There’s two of them offered by the module. Be exact when describing your problem.

1 Like

FastCast.new() is the one i am talking about

When I said “be specific”, I meant to run through exactly what you’re doing.

When you tell me “(thing) is broken”, that’s basically like going to a restaurant and telling the waiter “I want food”. Yes, I know that. You have to actually give me information about what it is that you’re doing, otherwise everything you’ve told me ends up being worse than useless.

What are you trying to do? What does the code look like? How are you using the function? Be specific and complete.

1 Like

Yeah sorry, my bad. here is the code:

local caster = FastCast.new()
local castparams = RaycastParams.new()
local castB = FastCast.newBehavior()

is it because i didnt space it out?

error: new is not a valid member of ModuleScript “Players.MrFernian.Backpack.Luger.Scripts.FastCastRedux”

edit: im literally stupid

robloxapp-20210804-2346299.wmv (1.6 MB)

How to fix this trail issue, and can it be fixed?

script for bullet move

function bullet.raymoved(cast,segmentOrigin, segmentDirection, length, velocity, bullet)
if bullet and cast.RayInfo.IsClient == true thene
	local bulletLength = bullet.Size.Z / 2
	local baseCFrame = CFrame.new(segmentOrigin, segmentOrigin + segmentDirection)
	bullet.CFrame = baseCFrame * CFrame.new(0, 0, -(length - bulletLength))
end
2 Likes

So I’m using the pierce function to pierce through humanoids that are already killed (so dead bodies can’t block bullets). Basically, if the health <= 0 then it returns true and pierces the body.

The problem is I keep getting this warning every time the bullet hits a “dead body” part.
WARNING: Exceeded maximum pierce test budget for a single ray segment (attempted to test the same segment 100 times!)"

Do you know why this might be and/or how to stop it? I’m assuming it keeps hitting the same part but wouldn’t the ray already be incremented forward by one increment already?

For reference, I don’t have a OnRayPierced function attached. If it does pierce, it doesn’t do any modifications such as bouncing. Also, the raycast filter is on a Whitelist.

1 Like

I take it you’re using the part cache module that comes with it right? I also take it you’re using trails for the bullet to make a bullet tracers? So basically, what you could do is disable the trail when it’s in the cache. When you fire a bullet, wait until the bullet actually comes down to the gun, and then enable the trail. So the trail doesn’t “come from the sky”.

TLDR; wait 1 heartbeat and enable the trail

3 Likes

I can’t get this to work for the life of me.

local FastCast = require(script.FastCastRedux)

FastCast.VisualizeCasts = true

local caster = FastCast.new()

local origin = workspace.TEST.FirePoint.WorldPosition
local direction = workspace.TEST.Orientation

caster:Fire(origin, direction, 10)

I’ve tried different values and nothing seems to work. The only thing that I know is that the VisualizeCasts’ CFrame is NAN (huge number). This script is under workspace. Everything looks like it’s working but it doesn’t visualize it correctly.
Am I missing something from the documentation?

EDIT : I figured out that the direction Vector3 was not giving the correct values. To go around this I made an attachment point and made it face the direction that I wanted to shoot using the WorldAxis to get the Vector3. Is there a way to get the Vector3 of a part the gives the same Vector3 as the attachment?
EDIT 2 : I found out that I need the LookVector. This took way longer then it should have. :sweat_smile:

1 Like

soo piercing is confusing for me. Not much documentation on the github for it, so I’m kinda at a loss of how to implement it. Whenever the pierce function fires, I check for a humanoid. If it detects a humanoid I call my damage function to calculate damage and do a bunch of checks. mind you my damage function DOES NOT yield whatsoever. But whenever I try calling it from the pierce function, the module returns an error about taking too long to complete. I’m probably over looking something, but at the moment I don’t know where to look for answers besides here. Originally, I thought it was my damage function, but after thoroughly checking it for any possible yielding or errors, I realized that surely was not it.

The GitHub documentation is obsolete and has been for a great deal of time. Use this instead: FastCast API, namely FastCastBehavior.CanPierceFunction

That error will occur if your pierce handler has not returned by the time the next ray simulates, which means that it was still trying to process that pierce operation when it was ready to move on.

Hello, I just have to say that I love this module. One question though, is it possible to make the velocity of the projectile be zero while it’s in the air? for example if I cast the projectile and then press a button, then the projectile stops mid air until I press that key again, is there any way to do that or is that not a feature yet?.

Hi, I’m using FastCast for a tennis game I’m working on, and I’ve noticed that whenever FastCast spawns an object, it increases the network receive rate a lot. (7-10 kbps per ball spawned)

Do you know what may be causing this?

I’m using a replication method that replicates the position and velocity of the ball every time it’s hit on the server (remote event fire to every client available to update their client cast), but even when I disable that, I noticed that the network data incoming rate (specifically Data) is unusually high.

I have a gif of it.

Any idea why this may be happening?

1 Like

In the API there is a Pause() and Resume() for an ActiveCast, when you do Caster:Fire() it returns an ActiveCast, so you’d have to maybe pool all active casts in a table, they delete themselves when the bullet hits so might work.

Thank you, I figured it out some time ago by reading the API.

Hello, when I try terminating an ActiveCast I get this error in the output, if needed I will elaborate on the conditions.
image

1 Like

You should always elaborate on the conditions and provide code. It’s a lot like calling me and asking for my help, and then putting me on hold once I ask what the issue is. Now I gotta wait on you to tell me the issue, and then maybe I can start being productive and working on an answer. Wastes both of our time.

1 Like

Sorry about that, The code is here

Caster.LengthChanged:Connect(function(Cast, LastPoint, Direction, Length, Velocity, Bullet)
    if Bullet then
	    if (LastPoint - NewTower.TurnPart.Position).Magnitude <= (TowerSheet.TowerShootingRange[TowerListNumber] / 2) then
		    local BulletLength = Bullet.Size.Z / 2
		    local Offset = CFrame.new(0, 0, -(Length - BulletLength))
		    Bullet.CFrame = CFrame.lookAt(LastPoint, LastPoint + Direction):ToWorldSpace(Offset)
	    else
	    	Cast:Terminate()
	    	print("Ray Terminated for out of range!")
	    end
    end
end)

My goal is to terminate the cast once it gets out of range.

Correct me if I’m wrong but in the FastCast API it says that you can set a max distance using FastCastBehavior.MaxDistance and it will automatically terminate the projectile when it goes out of range.

Link to source:

FastCastBehavior - FastCast API (etithespir.it)

1 Like

Thank you so much! I have been trying to create a limit to range and this is so helpful!