Making a proper projectile

Hello!
I am trying to make a projectile in my game, and while I do know how to do that, it is EXTREMELY clunky

The way it works currently is that a gun will have the bullet welded in front of it, or wherever it shoots from, and unweld the moment its fired

This works, but the problem is is that when things that arent supposed to interfere get in the way, like the gun model itself, and the player using it

Ive been using wait() so far to set its CanCollide and CanTouch to true, but again its very clunky

Is there a better way to do this? Thanks!

2 Likes

try different approach instead of projectile make raycast and color it to yellow so it will have simmilar things with bullet but more complex

This works for raycast based weapons, but some weapons fire in an arc, or a completely unique way

just color it to what you want

Some projectiles have unique shapes and structures, and again, they all move differently from eachother

do what you want but i advice you instead of projectiles use raycasting

Have you checked the relevant part of the documentation? If you want to use the bullets own collisions you’ll have to configure its collisions and then rely on that, whatever it hits is whatever it hits.
Then again, “projectile” ususally means projecting the bullets path, i.e. casting a straight ray (or shape) snd seeing what it intersects with. This too can be configured.

1 Like

Most projectiles are models, so I dont know how collision groups will handle that

i don’t think you’re understanding what he wants…

he doesn’t want to make a hitscan weapon that uses a raycast, he wants an arcing bullet

me personally, i would just clone a bullet model from serverstorage that has a script to go forward 'til it hits something

Thats what I do currently, but how would I go to not collide with the model itself or the player using it, and go at an arc?

Models are irrelevant, they are just a way to group parts together. It is shapes you are launching, those have a physical body that can partake in collisions and the corresponding properties. Then again, it should be enough trowing a simple ball as the bullet’s physical body, I doubt every part of an actual bullet model needs to be involved in collisions.

2 Likes

Look into fastcast, it offers the consistency and speed of raycasts while allowing for acceleration on the bullet, such as gravity.

1 Like

Ive heard of that before, but ill definitely look into it!

So here’s the basics of what you need for a bullet projectile:

First, operate on the client. The server will have an immense strain if it needs to keep track of dozens to hundreds of projectiles each second (roughly the average of an FPS game). When the client shoots, create a bullet part via localscript and then create a loop connected to RenderStepped. Preferably each bullet is contained in a table and ran under a single loop for performance’s sake, but I digress.

Each time the loop iterates, reposition the bullet forward by however fast you want it to go times the delta (time since last renderstepped). This makes it as smooth as possible on the client, while not inherently changing the bullet speed if the client has high or low FPS. There is more stuff you can add like add gravity and drag, I reccomend you get the basics done first though.

Now then there’s hit detection. Use a raycast that is shot from the bullet’s position from the last iteration and aimed at where the bullet currently is. If the raycast hits something, stop the bullet and fire to server. You can also use multiple raycasts for larger projectiles or ones with bizarre shapes.

Lastly the server’s role is to sanity check and tell other clients to replicate bullets. Make sure the client has enough ammo in their gun, they could reasonably have hit the target, and send the basic data of the projectile to other clients so they may create a visual-only version of it.

1 Like

Something like this + Shapecast maybe?

Using touched with a part is never going to be reliable enough. This should help you set up something that can reliably trace a path.