Hello users of the DevForum!
I recently created this wallbang ricochet system that is only a mere 60 lines. I thought it’d be cool to share it with you and see how I can improve.
Bullets and ricochet sensitivity are exaggerated to further make the effect more visible.
Time to create script: 12 minutes [1-2 hours fine tuning]
Benchmarks
Bullet Count: 1
Average FPS: 60
Bullet Count: 10
Average FPS: 60
Bullet Count: 100
Average FPS: 60
Bullet Count: 1000
Average FPS: 58
Bullet Count: 10000
Average FPS: 37
Bullet Count: 100000
Average FPS: 19
These benchmarks were ran on a Intel Core i5-3330 and NVIDIA GeForce GTX 750.
Results are heavily dependent on computer hardware.
For the people who want to know how this works:
In short, a function called DrawRaycastGroup
is called, which executes a for loop from 1 to the maximum walls that are able to be penetrated. If a result is returned from the raycast, then a bullet trial will be generated and the direction Vector3 will be slightly modified by adding a random number between -RicochetSensitivity
and RicochetSensitivity
. However, if no result is returned, then a trail will be drawn from the origin point to Mouse.Hit.p
[Mouse.TargetFilter
is set to Workspace
when the function is called, then set back to nil
when the function is complete] and the for loop will break.
The higher the RicochetSensitivity
, the larger the effect becomes apparent.
Feedback/suggestions are always accepted.