Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Methods for creating the best bullets?

Asked by 6 years ago

What is the most performance efficient way to make a bullet in a gun? With the context of performance being server stability and "No Lag", what's the best way to set up a gun to fire bullets in a Filtering Enabled environment? Something that can handle bullet drop off, bullet time, penetration, and perhaps particle effects on impact?

Would a normal part with collision turned off and velocity spiked way up in one direction handle this?

Is Raycasting the best way to go about it?

Are there other ways to do it?

0
I can't really help you much here, but I'd rather use a normal part with collision turned off, but if you're trying to cframe the part through a wall, the Touched event of an instance, which is a way of detecting parts touching each other, will not detect it Rare_tendo 3000 — 6y
0
Thanks for that heads up. Char187 0 — 6y
0
Just use BodyVelocity rather than CFraming it. KingLoneCat 2642 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

Hi Car187,

I recommend making a physical bullet and firing the bullet from the barrel of the gun to the position that the barrel is facing using the .lookVector of the barrel.

Use the following:

BodyVelocity

You make this inside of every bullet. The MaxForce should be set to math.huge() in all coordinates because bullets are supposed to be fast.

.lookVector

You use this for setting BodyVelocity's Velocity. With this you can make the part go in the direction a part is facing, which is what a bullet does when you fire it from a gun. It goes in the directi**on the barrel is facing.

A straight part on the barrel.

I recommend this because when you make a gun and model it and all, it becomes hard to tell which direction is straight with it, so I would just say you can either make an invisible non-colliding part right on the barrel, or just add a part to every barrel that faces straight in the direction the barrel is facing. You can find which direction it's facing by using a decal. One of decal's property is 'Face' and you can use this to detect which way is the front and I think the .lookVector uses the front side.


Why use this and not just raycasting?

Raycasting doesn't take into account proper physics that should affect a gunshot, like aerodynamics and such. Also, raycasting doesn't take into account the amount of time that it would take for the bullet to reach from the barrel to the target, and a target could possibly avoid dying if he/she is fast enough. The short reason is that raycasting doesn't have a speed you can set, but, BodyVelocity does. However, I can understand using raycasting because you are seeking ultimate efficiency over realistic goals. So, for efficiency over realistic system, I would say ray casting is pretty good then but, you will have many complaints possibly about it because it would limit gameplay but, increase smoothness. So, you have to choose of the better. You can reduce the lag with physical objects by using StreamingEnabled, so you can also have a balance but, StreamingEnabled has it's own limitations which you can find here.

Ultimately, I hope I helped.

Thanks,

Best regards,

~~ KingLoneCat

Ad
Log in to vote
0
Answered by 6 years ago

The best way to create realistic "bullets", to not actually use parts, but to use RayCasting.

0
To add onto this you can do bullet drop / bullet time with raycasts if you do multiple rays over long distance. simply make it convincing. cabbler 1942 — 6y
0
I disagree. With ray casting, moving targets become way easier to hit because you just click on them while they are moving but, it doesn't take into calculation the amount of time it takes from the barrel of the gun to the target. Because, if a target is moving it's possible that the target can avoid the shot. KingLoneCat 2642 — 6y
0
You can use math to compromise for that. optiplex123 21 — 6y

Answer this question