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

Well one thing may have been that each gun had a part cache of 500 rounds. I brought this down to 50 as I suppose that was an extreme overestimate.

However, I’m not sure what you mean by

Aren’t bullets meant to be apart of part cache on the server?

Nope, not necessarily. For my game the fastcast is on the client to handle the visuals only.

If it is on the server then everything has to replicate to the client including the bullets projectile motion for every position and orientation changes.

Vs telling the client once to create the bullet and then letting the client simulate by itself without needing the server to tell it every position and orientation change as the bullet travels.

I recommend you try it out yourself and see if it makes a difference.

This method of using fast cast on the client for client effects I took notes from FPS framework 2.

Isn’t this method vulnerable to exploiters though?

Also you mention the client handles the visuals. But if the client handles the visuals, how will the client see other clients bullets?

You could do this from detecting when the player shoots the gun, then the server will send data’s of the bullet (e.g: Origin, Direction, Velocity, etc) from the player that shoots to other players to draw the visuals (e.g: bullet model, bullet trace, etc), so basically

Client → Server → Other Clients

i can concur. Beastybeasty145’s comment is very useful for the task in my hand.


The issue appears to be workspace being nil.
What’s happening here? Do bullets have to be parented to something specific?

I decided to go with your advice and I managed to get some really interesting results. Send-Receive rates of under 1KB/s for both clients on both rates. However my only issue now is that spread is of course randomly generated which means that if the spread isn’t accurate enough for the receiving client, the attacking player will have killed the client but the defending client would be fine which is less than ideal. Thanks for the advice, Ill do my best to develop this system but I am not without my concerns as I am sure how to defend against exploits through this way.

1 Like

If anyone wants the provided Example Gun into a direct ServerScript, you can view how I did this here!

any good way to get spirals or circular motion? I’ve read that it could be a bad idea to update the cast physics every frame. assuming at most 50 projectiles on the screen, how expensive could this be? am I better off just using traditional hit detection?

Is there any way of simulating the ray instantly?

I’ve tried figuring this out myself, but haven’t been able to…Does anyone know why when the FirePointObject on the Tool seems to either collide or be very close to colliding with another part, the bullet will fire at a completely different angle?


Sorry for the small Gif, but this showcases what I mean. You can see my first few bullets fire in random directions when touching or nearly touching another object, as well as the last few bullets. You also see one shot actually go in the correct direction when I’m further away from the object.

3 Likes

Is it possible to simulate air resistance and drag with FastCast?

1 Like

This is a roblox issue with cursor detection sadly.
I personally have this issue with EVERYTHING thats cursor-based.

As far as I am aware there is no direct solution (I may be wrong)
You could attempt the following though.
~ Raycast from the camera origin to get the hit cframe of the mouse. (unsure if this will work.)
~ Or just detect if the gun is very close to something and make it shoot infront of the barrel by default instead of going to the cursor.

2 Likes

Hey, thanks for the response!

In a way, I believe I’m already doing what you’re suggesting, but slightly different. Rather than using the Cursor for getting the Mouse.Hit.Position, I began using a Raycast from the center of the screen and then returning that position.

local function GetCenterOfScreen()
    local position = Camera.ViewportSize / 2
	local unitRay = Camera:ViewportPointToRay(position.X, position.Y)

    local rayParams = RaycastParams.new()
    rayParams.FilterDescendantsInstances = {Character}
    rayParams.FilterType = Enum.RaycastFilterType.Blacklist

	local raycastResult = Workspace:Raycast(unitRay.Origin, unitRay.Direction * 1_000, rayParams)
	local hit = CFrame.new(raycastResult.Position)

    return hit.Position
end

Although even with this, the issue still persists, unfortunately.

I was curious if you had an idea of how to get the direction forward of barrel? Currently I calculate the direction using the following equation fireDirection = (mousePoint - FirePointObject.WorldPosition).Unit.

Additionally, for anyone else who might be curious about the issue, as my previous Gif might not have shown it off greatly, here’s a better one:

1 Like

If someone is still looking for this, there’s a thread solving this issue:

Simply copy & paste the entire code block, set up the proper arguments (bullet speed, gravity, start position etc.) and use what the LaunchDirection function returns as your direction argument:

local CanReach,DIRECTION = LaunchDirection(..., ..., ..., ..., true)

Caster:Fire(FirePointObject.WorldPosition, DIRECTION, modifiedBulletSpeed, CastBehavior)
3 Likes

I would absolutely love a method to simulate once instantaneously. Similar to just WorldRoot:Raycast(), it would be FastCast:Once() that would return a hit. This way I could have FastCast hit reg on client and have a sanity check testing the entire path, including pierces and reflections if I have those implemented. I’ve tried numerous times to do hit reg on the server but the delay is very noticeable and makes gunplay awful. I’ve tried lag compensation methods such as player snapshots, but it still doesn’t beat client hit reg.

1 Like

May i ask how do you use the pierce function, i have been trying to do ricochet for so long. thank you, sorry if im interupting your time

I have done this for only default projectile motion projectiles.

So it should work unless you are changing the acceleration or velocity after the projectile is in flight.

Sidenote:

But keep in mind to check out other lag compensation server sided solutions and such like CSGO and stuff.

Ultimately it’s up to you to decide.

2 Likes

I created a staff weapon that fires orbs of magic, and when one of these orbs intercepts a part with a “Shield” attribute they are reflected back to the original player. This works fine, but there is one caveat: the changes I try to make to some ray parameters don’t seem to work properly, specifically the FilterDescendantInstances property.

When a player uses the staff to fire a projectile, the caster is told to ignore their character’s model; when the projectile is reflected back, the script tries to override the filter list with an array only containing the character of the player who reflected the projectile. This would allow the reflected projectile to hit the player who originally shot it, but in practice it refuses to work. The projectile goes through the staff user’s character every time, even if I try setting the ignore list to an empty array.

What gives? Am I not meant to change this property in run time? The band-aid solution I have right now is to not place the staff user’s character in the ignore list in the first place, which isn’t great because you can occasionally hit yourself when firing a projectile.

Hey, thanks for replying!
I recently checked out your solution while back and I have tried implementing it, unfortunately I don’t believe I was setting it up properly. I will give it another shot and see if I can get it working properly!

Also, I looked towards games like CS:GO and tried implementing their lag compensation methods, it didn’t really turn out well and made server hit reg slightly better but still inconsistent.

Best regards,
Scythe

1 Like