Best way to Smooth Ballistic Physics?

I am projecting a gun that changes the camerasubject to the bullet when it’s fired until it hits something, creating an explosion and destroying the bullet.

Problem: server doesn’t replicate fast enough the Touched event changes to the client, making the bullet move for some extra seconds before the explosion happens, which kinda makes it a bit ugly to watch.

Edit: Take into account the bullets have low speed, and gravity is low, so people can see the bullet trajectory going slowly, and because of this arcs are formed.

I have a solution but I don’t know if it’s the best: I create an invis bullet on the server which will do the actual damage, and at the same time send a signal to all players to create a bullet with same trajectory that is just for visualization, with explosion effects and all.

Do you think there’s some problem with my solution and if so can you tell me another one?

1 Like

I used to utilize the .Touched event for weapon projectiles, but then I also came across this inevitable problem of client-server latency hassle. It was kind of annoying and I can definitely see why a lot of people instead use raycasting.
Your solution would work, but again there would be that inevitable lag between the server detecting a touch, and the client responding to that touch.
I suggest that you instead of using .Touched events for projectiles, use raycasting. With raycasting you can do a lot of things such as making rays to determine the projectile trajectory, what it hits, etc, more than simple roblox physics. And if you code it correctly, the difference of latency between the server and client can be unnoticeable.
Of course I’m not the biggest brain in terms of coding as this is my personal experience, so take this response with a grain of salt.

1 Like

It’s a low gravity, low speed ballystic game, so people are supposed to see the bullet going and making an arc, I could create a loop for raycasting the velocity of the bullet and checking the collision but I think it wouldn’t be precise.

what do you mean by smooth physics like TABS ballistic physics or like normal physics

Oh no, raycasting is a lot more precise than .Touched! (if not precise, a lot more reliable).

An example of a raycast can give you the position of the collision, the part colliding, the surface material of the part (kinda redundant), and the surface normal (this comes in real handy when you wanna make bouncing bullets n stuff).

And with that you can make bullet trails, effects, a lot of fun things too! Here’s a link to the developer wiki about raycasting. I hope it helps!

1 Like

The ballistic physics. Sorry I don’t know what TABS means.

uh its like another physics based game that the physics are more cartoonish like non realistic, like slow bullets ect.

That’s correct. It’s supposed to be more cartoonish, and turn based so people see the trajectory going to the player.

ok well in that case I would recommend using cframe or raycasting with that, I am not the best with that stuff but I do know they both will work.

Like I replied to cooldeath49, I think it will be unprecise checking like this, even with heartbeat/stepped, unless you mean creating a new physics system and rendering it with renderstepped using cframe, which I tried once for a golf game. Ball could even bounce from some parts but friction was a problem.
Note: bullets behave somewhat like on this game: Botzin Youtube

client:

  1. get cursor position in 3d space using a ray or Mouse.Hit
  2. send server that cursor position
  3. create a bullet on the client and start movement, then set camera subject to that bullet.
  4. if it hits, make it seem like the client dealt damage by showing a damage indicator. However, don’t actually have a remote to deal damage. The server will verify the shot and deal damage itself.

server:

  1. recieve cursor position from client
  2. sanity checks:
  • make sure player is actually looking at that position (prevents kill all exploits)
  • make sure there is a direct line of sight between the player who fired (prevent wallbang exploits)
  • make sure the position isn’t a single specific body part on the enemy every single time (prevent aimbot)
  1. tell all other clients apart from the player who fired to render a copy of that bullet, except with the start position as the new updated character’s position - this makes it look like the bullet actually came from the player if there’s high ping
  2. see if the raycast hit an enemy. if it does, use distance = rate * (currentTime - elapsedTime) to find the amount of time to wait before dealing damage.

This is a fairly common problem :slight_smile:

This seems like a well-made solution:

ok nvm then I was thinking you meant something like this at 8:15

That’s basically the solution I made, except I think that raycasting isn’t so appropriate for checking the damage on my case, because the bullets have some gravity, unless I constantly raycast and check on the trajectory. I tested with a yield of .5 seconds to fire client side with a simulated 250 ping and the diff from server to client wasnt so big. Guess I’ll end up using my solution.

1 Like

everything has its disadvantages, but I prefer using rays even if you need bullet drop.

firstly, you can account for this drop by offsetting the end position. it’s a lazy solution and there’s probably a better way to account for this (like what FastCast does, someone else posted it above) but that’s how I am with math :stuck_out_tongue:

I don’t remember what your original idea was, but incase it was .Touched, I’d recommend avoiding that. If the bullets are going fast enough, sometimes .Touched just doesn’t even fire at all.

5 Likes

Seems promising, I’ll try that too!

RayCast to the next position the bullet is moving to. Do this by updating the part’s position in a hearbeat loop and raycasting to it if there’s a part check if it’s a npc if it’s a npc damage it.

This solution is a very reliable solution as this is what I use in my gun system and as you see here there’s no problem with it.

https://gyazo.com/eee96e626219aa3a775fe85eefceedc2

What I do is simulate a projectiles with no models on the server which does the damage, the client creates a projectile to with a model, it raycasts to but just for visuals (destroying the bullet). The server also tells all the other clients to create this visual projectile

4 Likes