- I am making a combat system where when you punch you go a little forward.
- *i have tried using LinearVelocity, but it looks laggy, so when i switched to BodyVelocity it looked smoother.
When i try to use two bodyvelocity, one for the small dash attack, one for the knockback cause by the parry, the knockback doesn’t work; when i try to use one bodyvelocity and one linearvelocity, the knockback is all buggy, and when i use two linearvelocity it’s all good, but on other clients it is so laggy and not smooth.
What should i use, Linearvelocity or bodyVelocity or both?
local module = {}
local debris = game:GetService("Debris")
module.spawnLinearVelocity = function(char:Model, forwardSpeed:number, upwardSpeed:number, lifetime:number)
local humanoid = char.Humanoid
local humanoidRootPart = char.HumanoidRootPart
if humanoid and humanoidRootPart then
local attachment = Instance.new("Attachment")
attachment.Parent = humanoidRootPart
attachment.Position = Vector3.new(0, 0, 0)
attachment.Name = "LinearVelocityAttachment"
local linearVel = Instance.new("LinearVelocity")
linearVel.MaxForce = math.huge
-- Calcola la velocità combinata in avanti e verso l'alto
local forwardVelocity = humanoidRootPart.CFrame.lookVector * forwardSpeed
local upwardVelocity = Vector3.new(0, upwardSpeed, 0)
linearVel.VectorVelocity = forwardVelocity + upwardVelocity
linearVel.Attachment0 = attachment
linearVel.Parent = attachment
debris:AddItem(attachment, lifetime)
debris:AddItem(linearVel, lifetime)
end
end
module.enemyKnockBack = function(enemy : Model, knockBackForce : number, sourceLookVector : Vector3, lifetime : number)
local humanoid = enemy.Humanoid
local humanoidRootPart = enemy.HumanoidRootPart
if humanoid and humanoidRootPart then
local attachment = Instance.new("Attachment")
attachment.Parent = humanoidRootPart
attachment.Position = Vector3.new(0, 0, 0)
attachment.Name = "LinearVelocityKnockback"
local linearVel = Instance.new("LinearVelocity")
linearVel.MaxForce = math.huge
-- Usa la direzione in cui il colpo è stato effettuato (sourceLookVector) per calcolare la direzione del knockback
local direction = sourceLookVector.Unit * knockBackForce
linearVel.VectorVelocity = direction
linearVel.Attachment0 = attachment
linearVel.Parent = attachment
debris:AddItem(attachment, lifetime)
debris:AddItem(linearVel, lifetime)
end
end
return module
This is when I use two LinearVelocity, it’s not buggy, but it lags on other clients and it’s not smooth
https://vimeo.com/1000711652?share=copy