I’ve been working on a combat system heavily inspired by Smash Bros. with aspects such as knockback scaling and velocity.
One issue I faced when testing with other people or on my own in studio is that the BodyVelocities on the players were different on each others screens. On the screen of the player getting hit, it’s perfectly fine and works smoothly, but on every other player’s screen it’s delayed.
The BodyVelocity is created in a LocalScript which is in the character getting hit, through a RemoteEvent. The reason I chose to do this is because I have no idea how to make it smoother than that. Originally I had it in a ServerScript that was handling the attacks from the attacker. I thought switching to a LocalScript would somehow help but there was no difference.
I’ve tried using other methods to control character velocity, (ApplyImpulse, LinearVelocity, AssemblyLinearVelocity) but the results either stayed the same or did not work as I wanted. BodyVelocity is still the most reliable method for me.
Also, it’s very important for me to note that I’ve seen other devs use the EXACT same simple method; instancing the BodyVelocity, adding it to the HRP, setting its velocity and maxforce, then adding it to the Debris service, even some games instancing it on the server and not the client, with it working much more smoothly/without much delay. What am I doing wrong?
Video:
https://streamable.com/zd0zuw
This is what the localscript velocity handler on the receiving end looks like:
local remote = game.ReplicatedStorage.RemoteEvent
local char = script.Parent
local Debris = game:GetService("Debris")
remote.OnClientEvent:Connect(function(vel, duration, tweenData)
-- create and destroy the bodyvelocity
local bv = Instance.new("BodyVelocity")
bv.Name = "Knockback"
bv.MaxForce = Vector3.new(50000,50000,50000)
bv.Velocity = vel
bv.Parent = char.HumanoidRootPart
Debris:AddItem(bv, duration)
-- tween the velocity for specific type of moves (ignore this unless applicable to question)
if tweenData then
game.TweenService:Create(bv,TweenInfo.new(tweenData.tweenDuration),{Velocity=tweenData.tweenVelocity}):Play()
end
end)