Hi! I am the writer of the module in question (sorry for the late response, I don’t check the devforum much)
(I was summoned because of the link lol)
I gave most of the “gamer programmer documentation” in the module itself, but I didn’t explain how to use it to people who aren’t oop nerds lol
(aforementioned documentation)
But what does this all mean? And how do we use it?
first to use the module you need to require it
local WhizzyBullets = require(game.ReplicatedStorage.WhizzyBullets) -- require module
Because it’s an oop module it creates “objects”
each object can be thought of like an Instance, but purely in code, they aren’t visible in the explorer
The main type of object that gets created using my module is a “Bullet” object
To create a Bullet object you call WhizzyBullets.new()
you can also pass in a roblox Sound instance and a distance that the sound can be heard from
local WhizSFX = game.ReplicatedStorage.Assets.BulletWhizSound
--get WhizSFX from the assets folder, it gets cloned when it needs to be played
--so it won't be altered
local SFXDist = 10
--WhizSFX will only be heard within 10 studs of the bullet passing by your head
local Bullet = WhizzyBullets.new(WhizSFX, SFXDist)
This .new usage is what I detailed in the constructors portion of my documentation
Now that we have our Bullet object, what do we do with it?
Well according to our documentation we have two methods, Check() and Dispose()
Check is the way we would calculate the bullet whiz of a bullet
but theres one thing, the parameters it takes are weird! it takes an Origin CFrame and a Distance number, how the heck do we get that?
Well you can use WhizzyBullets.GetCFrameFromP0P1()
and GetCFrameFromP0P1 simply takes an origin position and a destination position!
so enough with the yapping, whenever you want to calculate the bullet whiz, you simply call Bullet:Check()!
--after the previous code block
local Origin, VectorDistance = WhizzyBullets.GetCFrameFromP0P1(Vector3.new(-100, 0, 0), Vector3.new(100, 0, 0))
--Get the Origin and VectorDistance if our bullet originates from (-100, 0, 0) and ends at (100, 0, 0)
local Distance = Bullet:Check(Origin, VectorDistance)
--Bullet:Check() returns the distance in studs the bullet is away from the player's head
--(nil if the bullet doesnt pass the player)
then finally we want to clean up our Bullet object after its been checked
Bullet:Dispose()
thats it! pretty much all there is to it!
now how would you use it in an actual game?
- Whenever a player shoots a bullet, you create a Bullet object
- Every time the bullet changes position you call Bullet:Check() with the old and new positions of the bullet
- If the bullets are hitscan you just need to call Bullet:Check() once! with the gun’s shoot position and the place the bullet hit
- If the bullets are projectile you need to keep track of the old bullet’s position across frames
- When you are done with the actual bullet (it hits something or gets destroyed), you need to call Bullet:Dispose() on the bullet object
theres one major caveat to note
this api is CLIENTSIDE, which means you need to create seperate bullet objects on each client
DONT create the bullet object on the shooter’s PC (we don’t want people hearing bullet whiz for bullets they’ve shot)
You can use a remote event that you fire for all clients when someone shoots