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

When I jump or am in midair, my cast won’t fire. Is this intented behaviour?

Hi, I have an issue;

Whenever I try to connect up RayHit to a ray hit function, it simply doesn’t fire the event at all and it doesn’t work. Here’s my code:

caster.RayHit:Connect(function()
	print('pew')
end)

Yes, I am 200% sure I fired the caster.
Yes, I am 100% sure I fired only one cast.
Yes, I am 100% sure I wired up the LengthChanged event.

@EtiTheSpirit Excellent module!

I had one question on the FastCastBehaviour instance. Its not clear to me from reading the docs that the API allows me to manage the size of the projectile after its fired. If I wanted the bullet template to say grow larger as it travelled is that possible within the current API? And if not do you have any recommendations for the cleanest way to manage that?

Thanks for making this! I don’t think the game I’m working on would be possible without it, and it certainly wouldn’t be so far along in development without it.

I have two questions for anyone who can help:

  1. How can I make the ray cast through players such that projectiles go through them?
  2. If I want a secondary fire functionality - which would necessarily behave differently - is it still best to avoid using a second caster?

Small suggestion:
Add projectile path prediction to simplify creating beams that indicate where the projectile will go.

1 Like
  1. You can edit the raycast parameters for the cast.
  2. I’m pretty sure that one caster would be enough, given that the projectiles are the same.

Hi
I have a remote that the client fires to tell the server it wants to fire a bullet. The server then handles the damage to other players of multiple guns in a central script. I’m stuck however at how I can get the player that fired the bullet from the serverscript.

I’m not supposed to add the RayHit connection under the OnServerEvent connection, so is there a way to pass information to Caster:Fire() that can be retrieved by Caster.RayHit()?

When receiving a remote event from a client to server, the first parameter on server is the player that fired it, So for Example

in a local script

Local RemoteEvent = -- to the remote event

RemoteEvent:FireServer() -- add some parameters to your likings

in a server

Local RemoteEvent = -- to the remote event

RemoteEvent.OnServerEvent:Connect(function(Player)
--do the fast cast here
End)

I believe this is the solution you wanted?

Yes, I can call Caster:Fire() inside the OnServerEvent, but how can I pass the player through to the RayHit event?

Connecting the event under the RemoteEvent is not an option, since it should only be connected once.

Well couldn’t you just make a new remote event and use that remote event in the RayHit event?

No a connection should only be connected once, not everytime the gun fires.

I believe UserData is what you’re looking for, it is:

A table where the user can store arbitrary information pertaining to this ActiveCast

so you can store the player when you fire:

SomeEvent.OnServerEvent:Connect(function(player)
    local cast = caster:Fire(origin, direction, velocity, behavior)
    cast.UserData.Player = player
end)

and then access it in the RayHit event:

local function onRayHit(cast, rayResult, velocity, bullet)
    local playerWhoFired = cast.UserData.Player
end
3 Likes

.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