Hello everyone, I am writing about a specific situation that I am currently facing. I’m trying to make a 2.5D Fighting game and is currently struggling with the knockback system. Now for clarification, the knockback DOES WORK but it doesn’t look well visually.
What do I mean by this?
Well take a look at the footage and see for yourself.
Notice on how one side, the knockback is instantaneously whilst the other is sort of sliding backwards? How can I make it so that both sides have that instantaneous feel.
Source Code:
local force = 25 * oppositePlayerHumanoidRootPart.AssemblyMass
game.ReplicatedStorage.Shared.SyncClientImpulse:FireClient(oppositePlayer, -oppositePlayerHRP.CFrame.LookVector*force)
This is happening server-side after the player successfully lands a hit.
local Shared = game.ReplicatedStorage.Shared
Shared.SyncClientImpulse.OnClientEvent:Connect(function(Direction: Vector3)
HumanoidRootPart:ApplyImpulse(Direction)
end)
Unrelated to your current problem
That moves the player on one client and not all clients so it’s better to do FireAllClients() so it appears for everyone
Are you sure this calculation is the same as the one done on the main client? Why don’t u pass the value from the main client to the server and to all other clients? Maybe that will make it more accurate?
I’ve tried to pass -oppositePlayerHRP.CFrame.LookVector*force to the server, but when I do it pulls the opponent forwards rather than backwards, I think it has to do with when the vector3 was initialized in memory, then sent to the server.
FireAllClients wouldn’t make sense due to ApplyImpulse being a client-only function, it wouldn’t make sense for me to also ApplyImpulse to the other player as the main client as it wouldn’t work.
Looking back at the videos attached, I think that problem is actually with the time of playing animations and not ApplyImpulse. You can see that the animations start at different times, if that isn’t the problem then I have no other solutions.
Actually I think I found the solution, I figured if I set the networkOwnership of the humanoidrootpart of the player, I can call applyImpulse on the attacking client’s side and that will be in sync for both players.