Trouble with making a hockey puck system

  1. What do you want to achieve?
    Hello, I have been trying to make a hockey puck system, sort of like the game Touch Hockey, where players can hit a puck around a rink. I have been having trouble with the physics, however.

  2. What is the issue?
    Currently, each time the player hits the puck, it either acts alright or incredibly janky and laggy. This is because the current system has the puck’s network owner set to the player that hits it. This makes it better than server physics, but it still acts janky and can be laggy if a client with a poor connection hits the puck. Also, I have attempted to implement a sort of cooldown system for whenever a player touches the puck to prevent them from hitting it multiple times, but this is probably just making it even more janky.

The main code that drives this is below, with this if statement being inside of a .Touched event and the ending remoteevent being fired to the player with the network ownership to then apply the force to it, which, if it matters and potentially makes it more janky, is the humanoid’s MoveDirection multiplied by 7 set to the puck’s AssemblyLinearVelocity. If you are wondering why I’m not using :ApplyImpulse, the puck can gain a ton of speed and then go crazy due to multiple hits in quick succession, but a fix might be able to allow me to use that instead.

if hit.Parent:FindFirstChild("Humanoid") then
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		
	if table.find(cooldowntable, player) then return end
	table.insert(cooldowntable, player)
		
	task.delay(0.2, function()
		table.remove(cooldowntable, 1)
	end)
		
	if puck:GetNetworkOwner() ~= player then
		puck:SetNetworkOwner(player)
	end
		
	game.ReplicatedStorage.Hit:FireClient(player)
end
  1. What solutions have you tried so far?
    As you can see, I tried not setting a network owner if the puck is hit by the same person, but the lag reduction appears to be minimal, if any. I also, like I said, tried to use :ApplyImpulse, but the puck gained too much speed.

So, my main question is, how do I make this system not janky, like Touch Hockey, where there are always smooth physics no matter what, with the puck not being able to be hit multiple times nor gaining too much speed to bug out? Am I doing network ownership incorrectly? Is the force being the MoveDirection of the humanoid the wrong thing to do? Is the cooldown system implemented poorly? Or, is anything else incorrect? I would greatly appreciate any help. Thanks.

1 Like

Could you provide a video to show how It reacts, as I know how the puck interacts with people in Touch Hockey.

1 Like

https://youtu.be/3fOm6tKWVmU

Also, we discovered another issue: if you “tab glitch” after hitting the puck, it completely freezes. This isn’t a huge issue in my case because this will just be a game for friends, but it would still be nice to probably fix it. Also, the puck is meant to be able to wobble, which is different from touch hockey, but unless that is making it buggy and poor, then that is indeed intended.

1 Like

An update: I decided to scrap using physics and network ownership altogether, and instead go for a CFrame approach. This works well, but the puck is jittery on the serverside, which is to be expected. However, I don’t know how I would replicate the puck onto clients without them desyncing, as I can’t use tweens due to the puck needing to constantly slow down and also being able to be hit by players and bounce off of walls. So, how can I replicate the puck onto every client without it desyncing too much with the server and the other clients? I understand that there will never be completely perfect sync due to network ping, but the puck shouldn’t completely desync by many studs.

Sorry for the late reply, but could you also provide video and code visualization, as I believe the best approach (as it is just a game between your friends I would most likely set the puck as its usual on the server.; however, receive the touches on the client side and set a remote event to be fired with a debounce per player this could solve the issue.

And sorry for a late reply to this, but I ended up roughly basically doing what you said. The server sends occasional remoteevents to update the puck’s position across all clients, and I smoothen it out on the client by getting the server’s puck speed and dividing it by the difference in Stepped vs RenderStepped. Other than the puck being a tiny bit stuttery at times, especially if the client is lagging, this works good enough for what I have to do, with most gameplay having the puck be very smooth.