Linear Velocity is weird

I want to use Linear Velocity to make a knockback for an attack. The velocity is supposed to go in front of the attacker but… The problem is this:

this is my code:

local linear = Instance.new("LinearVelocity")
linear.Enabled = true
linear.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
local att = Instance.new("Attachment")
att.CFrame = enemyChar.HumanoidRootPart.CFrame
att.Parent = enemyChar.HumanoidRootPart
linear.Attachment0 = att
linear.MaxForce = 60000
linear.PrimaryTangentAxis = Vector3.new(1, 0, 0)
linear.SecondaryTangentAxis = Vector3.new(0, 0, 1)
linear.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
local vec = c.HumanoidRootPart.CFrame.LookVector 
linear.PlaneVelocity = Vector2.new(vec.X, vec.Z)*120
linear.Parent = enemyChar

In order to achieve this, you will need to calculate a vector that points in the direction the attack is coming from. Assuming that c is the attacker’s character, you can go about calculating the direction vector like this:

local direction = (enemyChar.HumanoidRootPart.Position - c.HumanoidRootPart.Position).Unit

Then use this vector to calculate the PlaneVelocity for the LinearVelocity object:

linear.PlaneVelocity = Vector2.new(direction.X, direction.Z) * 120

The MaxForce is pretty high. I would try adjusting the MaxForce and see how much of a difference that makes. Keep it no more than 10,000 to test. If it’s too little, I would maybe keep it less than 25,000

I have tried both things but for some reason the character is just rotating and doesnt move anywhere

Try this code.

-- assuming c is the attacker's character
local vec = c.HumanoidRootPart.CFrame.LookVector
local knockbackSpeed = 120 -- adjust as needed
local knockbackDirection = Vector2.new(vec.X, vec.Z).Unit -- normalize the vector
local linear = Instance.new("LinearVelocity")
linear.Enabled = true
linear.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
local att = Instance.new("Attachment")
att.CFrame = enemyChar.HumanoidRootPart.CFrame
att.Parent = enemyChar.HumanoidRootPart
linear.Attachment0 = att
linear.MaxForce = 60000
linear.PrimaryTangentAxis = knockbackDirection
linear.SecondaryTangentAxis = Vector3.new(0, 1, 0) -- set to up vector
linear.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
linear.PlaneVelocity = knockbackDirection * knockbackSpeed
linear.Parent = enemyChar

Error : Unable to assign property PrimaryTangentAxis. Vector3 expected, got vector 2

Ah sorry, this should work x

-- assuming c is the attacker's character
local vec = c.HumanoidRootPart.CFrame.LookVector
local knockbackSpeed = 120 -- adjust as needed
local knockbackDirection = Vector3.new(vec.X, 0, vec.Z).Unit -- convert to Vector3 and set Z component to 0
local linear = Instance.new("LinearVelocity")
linear.Enabled = true
linear.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
local att = Instance.new("Attachment")
att.CFrame = enemyChar.HumanoidRootPart.CFrame
att.Parent = enemyChar.HumanoidRootPart
linear.Attachment0 = att
linear.MaxForce = 60000
linear.PrimaryTangentAxis = knockbackDirection
linear.SecondaryTangentAxis = Vector3.new(0, 1, 0) -- set to up vector
linear.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
linear.PlaneVelocity = knockbackDirection * knockbackSpeed
linear.Parent = enemyChar

Error: linear.PlaneVelocity needed vector2 but it got vector 3
so i did this

linear.PlaneVelocity = Vector2.new(vec.X,vec.Z).Unit * knockbackSpeed

but for some reason the turn happens regardless and now sometimes he gets fling, which is something

External Media

Chileee that ain’t a solution! What I gave you wasn’t 100% the answer because what you described didn’t really map out in my head, can you please describe what you wish to achieve again? x

The goal is to knock or send the other player a set distance from the attacker in a horizontal direction when hit by an attack

This is the best I could do, I tried my best modifying the code! If there are errors please let me know.

-- assuming c is the attacker's character
local vec = c.HumanoidRootPart.CFrame.LookVector
local knockbackDistance = 10 -- adjust as needed
local knockbackSpeed = 120 -- adjust as needed
local knockbackDirection = Vector3.new(vec.X, 0, vec.Z).Unit -- convert to Vector3 and set Z component to 0
local knockbackVector = knockbackDirection * knockbackDistance -- calculate the knockback vector
local linear = Instance.new("LinearVelocity")
linear.Enabled = true
linear.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
local att = Instance.new("Attachment")
att.CFrame = enemyChar.HumanoidRootPart.CFrame
att.Parent = enemyChar.HumanoidRootPart
linear.Attachment0 = att
linear.MaxForce = 60000
linear.PrimaryTangentAxis = knockbackDirection
linear.SecondaryTangentAxis = Vector3.new(0, 1, 0) -- set to up vector
linear.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
linear.PlaneVelocity = knockbackVector / (1 / knockbackSpeed) -- calculate the knockback velocity
linear.Parent = enemyChar

Unable to assign property PlaneVelocity . Vector2 expected got vector3

Omigoshh I made the same mistake chile it occurred because the PlaneVelocity property of LinearVelocity requires a 2D vector and not a 3D vector, I converted the knockbackVector to Vector2 before assigning it to PlaneVelocity, I hope this works.

-- assuming c is the attacker's character
local vec = c.HumanoidRootPart.CFrame.LookVector
local knockbackDistance = 10 -- adjust as needed
local knockbackSpeed = 120 -- adjust as needed
local knockbackDirection = Vector3.new(vec.X, 0, vec.Z).Unit -- convert to Vector3 and set Z component to 0
local knockbackVector = knockbackDirection * knockbackDistance -- calculate the knockback vector
local linear = Instance.new("LinearVelocity")
linear.Enabled = true
linear.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
local att = Instance.new("Attachment")
att.CFrame = enemyChar.HumanoidRootPart.CFrame
att.Parent = enemyChar.HumanoidRootPart
linear.Attachment0 = att
linear.MaxForce = 60000
linear.PrimaryTangentAxis = knockbackDirection
linear.SecondaryTangentAxis = Vector3.new(0, 1, 0) -- set to up vector
linear.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
linear.PlaneVelocity = Vector2.new(knockbackVector.X, knockbackVector.Z) / (1 / knockbackSpeed) -- convert to Vector2 and calculate the knockback velocity
linear.Parent = enemyChar

Hm it seems to have made the rotation bigger??? what may be causing this?

Could be that LinearVelocity is affecting the target player’s velocity in a way that causes them to rotate. We can add BodyAngularVelocity to the target player’s humanoid, something like this:

-- assuming c is the attacker's character
local vec = c.HumanoidRootPart.CFrame.LookVector
local knockbackDistance = 10 -- adjust as needed
local knockbackSpeed = 120 -- adjust as needed
local knockbackDirection = Vector3.new(vec.X, 0, vec.Z).Unit -- convert to Vector3 and set Z component to 0
local knockbackVector = knockbackDirection * knockbackDistance -- calculate the knockback vector
local linear = Instance.new("LinearVelocity")
linear.Enabled = true
linear.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
local att = Instance.new("Attachment")
att.CFrame = enemyChar.HumanoidRootPart.CFrame
att.Parent = enemyChar.HumanoidRootPart
linear.Attachment0 = att
linear.MaxForce = 60000
linear.PrimaryTangentAxis = knockbackDirection
linear.SecondaryTangentAxis = Vector3.new(0, 1, 0) -- set to up vector
linear.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
linear.PlaneVelocity = Vector2.new(knockbackVector.X, knockbackVector.Z) / (1 / knockbackSpeed) -- convert to Vector2 and calculate the knockback velocity
linear.Parent = enemyChar

-- add a BodyAngularVelocity to prevent rotation
local bodyAngularVelocity = Instance.new("BodyAngularVelocity")
bodyAngularVelocity.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
bodyAngularVelocity.P = 100000
bodyAngularVelocity.AngularVelocity = Vector3.new(0, 0, 0)
bodyAngularVelocity.Parent = enemyChar.HumanoidRootPart

Ok so it does seem that somehow the linearVelocity is affecting the target player in a way that makes them rotate, we can now actually get moved, although now this is really weird


I also adjusted the knockbackspeed

Ain’t that what you wanted? It seems proper fine to me x

the goal was to only move the player on the x/z axis, the y axis ideally should be left to gravity alone

Ah! Well I’m in bed rn so I’ll try helping out tomorrow, I’m glad I could help a bit x

1 Like

you should def try this


local Direction = -HumanoidRootPart.CFrame.LookVector --- the knock direction (in this case is the back direction)
local Power = 30 --- power of knockback

local LV = Instance.new("LinearVelocity")
LV.Attachment0 = Attach
LV.ForceLimitMode = Enum.ForceLimitMode.PerAxis
LV.MaxAxesForce = Vector3.new(1,0,1)* 50000 ---- force will only take effect in X and Z ignoring the Y one.
LV.VectorVelocity = Direction * Power
LV.Parent = Character

Adjusting the AxesForce is very helpful when you want to set force, only to specific coordinates.
Sorry for replying 1 year later, hope this help someone.