Hi. Basically, I want to make my gun kit shoot bullets directly from the muzzle and go where it’s pointing, not where the mouse is positioned. I’m using the fastcast module, and I somewhat cracked it, however, the bullets act weird, not moving where they’re fired from even if I change that in first person.
[note: I would’ve recorded this but my gyazo broke and I dont have any other software to record stuff, sorry]
I tried to look for some solutions to this but I couldn’t find any.
Here’s the code I used to work out the firing direction for Fastcasting:
local rayPosition = muzzleOrigin.WorldPosition
local rayDirectionOld = -(tool:WaitForChild("BodyAttach").CFrame.Position - muzzleOrigin.WorldPosition).Unit
You are defining rayDirectionOld but you send rayDirection, not sure if that has anything to do with it.
I have no experience using fast cast, but I’d imagine the way to go is getting the barrel position and getting which direction it is facing and shooting in that direction.
Hi, thanks for replying. rayDirectionOld is the variable I use for the base direction, and then I do some calculations for spread and such under the rayDirection variable.
I tried that, but it was really glitchy and broke. I’m using an attachment for the muzzle/barrel position, not sure if that has anything to do with it?
Try creating an attachment on the tip of the barrel (with its parent being the barrel) and use that attachment instead. Might be that the attachment you are currently using is relative to the character and not the gun.
Thanks for the idea! It’s fixed the crazy increase of height in the projectiles, however, they still don’t come out as expected when I point the gun up/down.
is the attachments position restored in the variable each time it’s shot? and if so, is there a delay between the bullet being fired and the attachments position being declared?
Yes, the attachment positions get restored every time the gun is fired (I fear that may have some lag problems but I haven’t seen any yet), and there’s no delay except for calculations
Ok, I’ve printed the attachment positions, and it doesn’t change when I move about in first person. I think it may be because the gun gets moved around only on the client. I’ll have to make a server sided arms system I think. Thanks.
YEP! I’VE FIXED IT!! Thank you all so much for your help!! I’ve been stuck on this all day and it was so simple, thank you very, very much everyone!
I also made it so the client fires the position of the attachments in the projectile event, therefore it gets the position of the attachments on the client, working with the first person arms.
You’ll have to either let the client send the position of the barrel (uh oh) or you have to make it server sided. Having it server sided should make the game look better though since people turning around is visible for everyone!
I see you chose to send the position!
Make sure to make sanity checks for the position of the attachments so exploiters won’t be able to cheat as easily!