-
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. -
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
- 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.