I have a few questions about optimization when it comes to FPS systems.
The system I have right now uses a local script for mouse input, does client to server where it will play the animations, and based on what character you are, it goes to the module script that has the data for that character (if it has any specific logic i want to run when the bullet hits something, damage, speed, etc) and then does ANOTHER module to module where this next module does bullet logic.
I need help figuring out if this is an efficient system.
Right now, all my bullets that move in a linear motion are held in a single table, and moved each frame with a single loop.
Right now, I just need a method of optimization, not really code. How would I make the bullet visuals client-side without having to wire up tons of remote event spams?
I would recommend looking up a method called “hitscan”. Manually tracking each projectile is overkill. Bullet visuals should be client-only. The server only needs hit information from the hitscan and it may do other validations.
@jonbyte Alright, I MIGHT understand.. I’m not sure.
I create a startPos on the server, speed and direction. I find the nextPos: Direction * speed * DeltaTime (i think that’s right hopefully) and each frame that goes on, i would do a raycast in between the currentPosition and the nextPosition, if there is something blocking the NextPosition from the raycast, delete it. This is on the server logic side for damage and stuff like that. No need to rely on using the physical bullet part for position and stuff for that part.
But if I wanted to delete the visual projectile on the client when it hits something, I could either do a remote event where the server tells the client to delete the bullet since it touched something, or I could possibly just do the same ray logic on the client, but only delete the visual bullet when the ray is touched.
Some of the bullets in my game are slow moving (like rocket launcher bullets,) so I would have to delete them the moment that they get hit so it doesn’t look odd.
Would this be correct?
@jonbyte Thanks a lot. I went from a character that did tons of exploding tweens and craters and flinging parts bringing the Server Receive up to 40 kb/s each shot to only 2 kb/s each shot. All visuals are now on the client and it’s fixed.