Best way to achieve smooth ball physics?

Hello everyone. I want to make a volleyball-ish game that relies on smooth ball physics but also accurate client-server synchronization. Take the games Volleyball 4.2 or Death Ball as examples.

I’ve been thinking about how I should do it for a while now, but I can’t decide between writing my own physics handler (with shapecast for collisions) or simply using Roblox’ physics engine. My question to the community is: which option would be more suitable for my use case (smoothness & replication)?

Thanks in advance.

2 Likes

I would recommend and tweening instead of using roblox physics because roblox physics is much more performance intensive and although it’s improved it can still be inaccurate. Plus it can alwyas be exploited.

But if you were to use roblox physics/tweening, the smoothest you can get is setting the network ownership to the player and using the physics/tweening on the client that owns the ball.

But again, that can easily be exploited.

So your best bet to be safe + smooth is to tween + fireallclients.

You can also make your own physics if you want but tweening imo is better

2 Likes

As for security, I could always have the real ball on the server and have the clients replicate it themselves.

I also notice that most games use tweening - my question is, how would I detect collisions with it? Do I just raycast in the direction of velocity? I feel like that would work. Thanks for the quick answer btw :heart:

2 Likes

Yeah I’m pretty sure it’s raycasting, because .Touched would be inaccurate. It could be getpartsboundsinbox aswell.

I say just do raycasting though because with raycasts you can do more things with the intersected object rather than getpartsboundsinbox.

3 Likes

Oh yeah of course but still roblox physics is pretty jittery unlike tweening/lerping.

2 Likes

Isn’t tweening every frame super laggy tho? Or not

1 Like

Yeah that’s why you should use lerping if you’re doing it frequently.

1 Like

How often do you think I should update the clients?

1 Like

Only when the ball is moving. Therefore I think a while loop would be preferred over runservice because runservice just keeps running over and over. Which could cause performance issues due to the amount of times the remote event is fired. Whereas, while loops can run only under certain conditions.

1 Like

What do you think of this idea?:

  1. Ball spawns on server, FireClients the initial data such as position and velocity
  2. Clients and the server both run the same movement simulations
  3. The server sends pings in regular delays to keep the clients synchronized

I think this approach would allow a lot of smoothness and performance optimization

Edit: I will try this approach and update you

3 Likes

That’s what i did for my dodgeball game, and it works very smoothly.

1 Like

Even under high ping situtations?

Could you send a video or could I test it

1 Like

Yeah I think this would be the a great idea, I never thought of that.

One issue may possibly be the “delays”, the delays should be relatively small because this could cause the time taken for the client to send info to the server and back to increase.

1 Like

Yeah could you send a video, I’m interested to see how it looks.

1 Like

This is my current implementation - it syncs the position and velocity on every hit. I don’t use tweening yet - I just have a module script that handles simulations and run that on both server and client. Tho I feel like the transition is choppy and could be improved, I don’t know how tho.

EDIT: The transition is choppy because on every hit, I make sure the ball stays above ground and doesn’t clip into the floor. I can make this smooth by lerping but it lets the ball enter the ground a little. I really don’t know any other solution

1 Like

use alignPosition on an unanchored ball (only for the client)

1 Like

I found his game join up lets see if he was lying

image

image

edit: bro lied

2 Likes

verdict: the balls use roblox physics

3 Likes

the music really ruined my mood ngl

2 Likes

Well im currently also making a game that involves a ball and the way I’m doing it which is working super well is I have the ball be anchored but it has a BodyPosition inside of it, and then I run custom simulation code on the BodyPosition, and because the server is doing the simulation it’s going to be in sync on all clients aswell as smooth because it’s a BodyMover

I’m currently doing some testing with Automatic Network Ownership and Setting it to the player when a certain condition in my game is met but I havent figured out which one is the best

1 Like