Hello, could you give me the game’s link or a video, at least? I’m very curious about it(yes, this post is from like 3 years ago but…)
Do you know if it’s possible to remove the bouncing?
How would you set a max speed for a projectile?
there is a “bullet-speed” value, and im pretty sure bullet isnt allowed to pass that limit
Is there a way to remove the cosmetic bullet entirely to improve performance or do I have to make the bullet invisible?
I do not expect a yes for this though since most people tend to make the projectile visible.
Remove the Reflect function since you don’t need it.
local function Reflect(surfaceNormal, bulletNormal)
return bulletNormal - (2 * bulletNormal:Dot(surfaceNormal) * surfaceNormal)
end
Remove everything in CanRayPierce function or remove the entire function if you don’t need it.
function CanRayPierce(cast, rayResult, segmentVelocity)
local hits = cast.UserData.Hits
if (hits == nil) then
cast.UserData.Hits = 1
else
cast.UserData.Hits += 1
end
if (cast.UserData.Hits > 3) then
return false
end
---- this part could be use later for doing damage.
local hitPart = rayResult.Instance
if hitPart ~= nil and hitPart.Parent ~= nil then
local humanoid = hitPart.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:TakeDamage(10)
end
end
----
return true
---- this part can be use for piercing/penetration and this part is originaly disabled that is replaced by bouncing.
if material == Enum.Material.Plastic or material == Enum.Material.Ice or material == Enum.Material.Glass or material == Enum.Material.SmoothPlastic then
-- Hit glass, plastic, or ice...
if hitPart.Transparency >= 0.5 then
-- And it's >= half transparent...
return true -- Yes! We can pierce.
end
end
----
end
Remove everything in OnRayPierced function or remove the entire function if you don’t need it.
function OnRayPierced(cast, raycastResult, segmentVelocity, cosmeticBulletObject)
local position = raycastResult.Position
local normal = raycastResult.Normal
local newNormal = Reflect(normal, segmentVelocity.Unit)
cast:SetVelocity(newNormal * segmentVelocity.Magnitude)
cast:SetPosition(position)
end
How to do cosmeticbullet on client so no lag, but still have it replicated to server? Would you just create the bullet on the client and fire and also fire it on the server? But then if there is lag, wouldn’t the bullet on the client and the bullet on the server be seperated, not in sync for the client?
Fire a bullet on the client.
Send position and direction to the server.
Server replicates it to all other clients.
Other clients fire the bullet from the given position and direction.
correct me if I’m wrong, this is what ur saying:
. Fire and calculate the physics for the cosmetic bullet on da client
. Then send da position and da direction to da server (where da server will do if checks to see if the request is reasonable and not a hacker exploiting remotes), where it to can fire a ray but not fire a cosmetic bullet and also see if anything hit da ray and then damage it.
. then on ur last dat point u said fire the bullet on all da other client, meaning when the original client that fired the bullet sends the direction and position to the server, the server loops through all the players and sends information from server to client to also fire this bullet on the rest of the clients?
Yes, the bullet will be smooth on all clients that way.
Just a quick question, @EtiTheSpirit is there a way for the ray casting to ignore player accessories? Normally it looks like the example gun treats accessories (like a backpack or a vest) as a part and just bounces off deals no damage. Is there a simple property I can change to fix this (like a blacklisting thing or something), or is this a more complex issue?
Edit: I already fixed this by setting the collision group id of the accessories to one different from the bullet object
I’m having one caster on the client that handles all visuals for every projectile in the game. With the occasional server caster created for specific weapons. Is this an ok way of setting it up?
Prolly late but you could weld parts together and then parent one to the other.
welds are gross I just adjusted the FastCast source
Weld constraints are swag doe. What did u do? Like edit it to pivot model or somthing
Hi, I now have an issue where for some reason the bullets do not ignore what they are supposed to and the ray hit event is fired and the ray is terminated. I don’t konw what the problem is.
Please show the code that is firing the bullet.
Hey, so i’m having difficulties getting the pierced function to call a function that returns a value. Basically I have a function that damages the player based on the values passed through the function, which then returns a string. There are no yields in the damage function, so the function shouldn’t yield, yet it acts like it is. I know for a fact it’s not my code because when I created a blank function that only returns a string, it did the same thing. Here’s my code.
castbehave.CanPierceFunction = function(cast, result, segmentVelocity)
local hit = result.Instance
local character
if hit.Parent.Name == "Stand" then
if hit:GetAttribute("TruePart") == true then
character=hit.Parent.Parent
end
else
if hit:GetAttribute("TruePart") == true then
character=hit.Parent
end
end
if result and result.Instance and explode == false then
if character then
coroutine.resume(coroutine.create(function()
local checked = Hurt(player, character, 5,character.HumanoidRootPart.Position , 5, math.rad(25))
if checked == "TookDamage" then
EffectsFunction:FireAllClients("ElectricAttack", character:FindFirstChild("Humanoid").Parent, damage, character:FindFirstChild("HumanoidRootPart").Position)
end
if checked == "Shielded" then
EffectsFunction:FireAllClients("DamageBlocked", character:FindFirstChild("Humanoid"), damage, character:FindFirstChild("HumanoidRootPart").Position)
end
if checked == "Countered" then
end
end))
end
return true
else
lc:Disconnect()
return false
end
end
This is going to be really helpful for me any many others. Thanks for sharing!
As much as I’d want to use this module, there is not enough documentation and support for my needs. Luckily, My game doesn’t use tons and tons of projectiles, so developing my own system wont be that hard or inefficient. I’m happy there is a solution for tons of projectiles, but it simply doesn’t have the features that warrant the use of this in my development. I recommend taking some pointers from RayCastHitbox, as they constantly update their module, and have tons of features, all with examples and documentation.