Fastcast bullet trail not appearing from muzzle

Hello, i’ve been searching for hours for a solution to this video:

As you can see, the bullets doesn’t start from the muzzle, it has an offset that is unwanted. (I’m using fastcast)

Here is my code:

I have found no solution to this problem, please help!
If more screenshots are needed, please feel free to ask!

Try making the bullet wait a bit after spawning before moving. I am able to recreate your issue and fix it too for my own projectile framework:

How can i adapt that what you did in my script? I dont understand anything about your script, so can you please give me an idea on how to implement it ?

For your onCosmeticLengthChanged function, you can pass an additional parameter that declares if the projectile had just spawned in. This parameter would only be true the first time that the function is called for that particular projectile. If the parameter is indeed true, then you will skip the bullet.CFrame = ... statement.

2 Likes

The thing you said somewhat helped me solve my problem, thanks!

In case someone has the same problem than me, here is a solution:

Length determines the distance the cast has already traveled, so i only apply the offset once the length is more than 40 studs(?

That way the offset is delayed, and the problem, solved.

EDIT 1 Year later: Since there have been some people that have been PMing me because they can’t find a solution, I scripted a place where it contains the original solution that @prototrode gave.

FastCast Example.rbxl (78.4 KB)

It contains the most basic code that a fastcast weapon can have, so just use it ONLY as an example!

ReplicatedStorage contains the fastcastRedux module, and a template bullet.
Inside the example tool that is inside StarterTools, you will find a LocalScript that contains the solution for this problem. You can also test it playtesting the file.

EDIT 2: I forgot to include some explanation that I included with the original response for the dev that needed it originally:

<------->

Okay so, the thing is that the solution that @dthecoolest gave in my other post has an “algorithm” that works like this:

FastCast Redux has some callbacks when casting, which are:

  • LengthChanged (To update the cosmetic bullet)
  • CastTerminating (Called when the casting ends, even if it didnt hit anything)
  • RayHit (Called when casting hits with something)

The thing is that, when the cast hits something before 2 frames have passed, it can’t register the trail from the bullet template, so what the solution does is that it uses task.wait and sets manually a cframe to help the client process the trail.

So, in the callback from “RayHit”, it detects if the active cast has processed at least more than 2 frames, and if not, it will manually cframe the bullet with task.waits and making the sum between the original position and a lerped position (2 times x0.5 to make x1 so the trail is visible). The code would look something like this:

local function OnRayHit(ActiveCast, Result, Velocity, Bullet)
	if ActiveCast.UserData.Frames <= 2 then
		local direction = Result.Position - Bullet.Position
		local originalPosition = Bullet.Position
		
		-- Sets the target position x0.5
		task.wait()
		Bullet.CFrame = Bullet.CFrame + direction * 0.5
		
		-- Sets the target position x1
		task.wait()
		Bullet.CFrame = Bullet.CFrame + direction * 0.5
	end
end

If you don’t know what ActiveCast.UserData is, then it’s simple: UserData is a default table that FastCast gives to any ActiveCast, so you can set data there to link them between lines of code that aren’t in the same function or similar. Personally i use that table to set if a bullet is replicated in the function Cast(), that way i can check in the OnRayHit() function if the cast is a replicated one or an original one.

I heavily recommend to take a look into the original fastcast API Docs, it’s really useful! ;D
https://etithespir.it/FastCastAPIDocs/

<------->

Cheers, everyone! ;D

5 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.