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

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!

Update: When it goes out of range the ray terminates but not the projectile part, how do I fix this?

1 Like

Couldn’t you connect to CastTerminating, and destroy it there?

2 Likes

Well how would I get the projectile instance from CastTerminating?

Yep this is a common question, because the api doesn’t explicitly provide the cosmetic bullet object in cast terminating as one of the parameters so it’s not as obvious.

However it’s possible through the activecast object like so:

Cast terminating bullet clean up with PartCache
		local function cleanUpBullet(activeCast)
			local bullet = activeCast.RayInfo.CosmeticBulletObject -- API wise it's pretty weird compared to OnRayHit event.
			--Debris:AddItem(bullet,1)--normal instance.new clone
			local trail = bullet:FindFirstChildWhichIsA("Trail")
			if trail then
				trail.Enabled = false
			end
--If you use part cache to clean up
			projectileCache:ReturnPart(bullet)
		end

		castComponent.CastTerminating:Connect(cleanUpBullet)
1 Like

Thank you for this! I can finally get past the range mechanic and continue progressing on my game!

I’ve been working on a rebuild of FC on and off recently. I will address this in the new API once it’s all released. No ETA, since my job takes precedence.

2 Likes

Hi Eti, I wanted to ask, will you add support for bigger hitboxes anytime soon? I’ve been using your module for a while, but for projects that require ranged abilities with bigger hitboxes, I can’t use it, and it’s a huge bummer since it’s the only thing i can think of using for ranged attacks or weapons.

What’s the recommended way to add a “lifetime” for the bullet (i.e. to purposefully proc the CastTerminating event after x seconds)?

I’ve decided to use FastCast in a project but the issue is it seems really expensive. I have multiple weapons in my game so in the server I’m looping through the data for the weapons and creating casters and cast behaviors for each one as well as establishing their respective events. I have a single remote event for when any weapon fires and find the caster setup for that weapon and use it to fire the weapon. This feels expensive though. Is there not some better way to do this?

Do the caster setup entirely client sided. Attach caster objects to instances via a dictionary to keep track and avoid having to create a new caster object.

On the server use projectile logic based sanity checks

1 Like

Hi, Excellent module! Yielding good results for my project right now.

On another note, I am curious, why do you use your own website for the API instead of GitHub, I see the github page you had set up is obsolete now. Just curious.

Thank you for the contribution to the community!

Is there no support for multipart projectiles when using PartCache? My bullet consists of two mesh parts but I can’t seem to use a model because PartCache only accepts a BasePart.

I’ve faced the same issue, I had to change my projectile model to a single mesh. I don’t think there’s any support for Model projectiles yet.

1 Like

Hey! I just want my CosmeticBullet to go “straight” (like a knife should go) but it gets thrown from aside.

Like this:

I tried to change the CosmeticBullet orientation directly from the Properties in the union (my CosmeticBullet is an union) and also via script (tried out with .fromMatrix and some lookAt functions but nothing works). Why can’t I change the orientation and how can I fix it?

ty!