Help with Linear Velocity

I’m making a kick system where you can kick another player that you are paired with. My issue is that I can’t figure out how to make the Linear Velocity head straight where the other player was facing. The power is perfect and works as expected it just always goes in the exact same direction even when the player kicking does different angles.

Problem is on the line where I assign the linearVelocitys VectorVelocity.

local function kick(player, otherPlayer)
	local IsPaired = ServerStorage.Functions.CheckPair:Invoke(player, otherPlayer)
	if IsPaired == true then 
		if not table.find(Debounce, player.UserId) then 
			table.insert(Debounce, player.UserId)
			local character = player.Character or player.CharacterAdded:Wait()
			local otherCharacter = otherPlayer.Character or otherPlayer.CharacterAdded:Wait()
			
			local linearVelocity = Instance.new("LinearVelocity", character:FindFirstChild("HumanoidRootPart"))
			local attachment = Instance.new("Attachment")
			attachment.Parent = character:FindFirstChild("HumanoidRootPart")
			linearVelocity.Attachment0 = attachment
			linearVelocity.MaxForce = math.huge
			linearVelocity.VectorVelocity = otherCharacter.HumanoidRootPart.CFrame.LookVector + Vector3.new(0, 100, -100) 
			
			task.wait(0.5)
			linearVelocity:Destroy()
			local index = table.find(Debounce, player.UserId)
			table.remove(Debounce, index)
		end
	end
end

I appreciate any help that you guys can give.

Did you try multiplying the look vector?

what you’re doing here is adding a flat amount to set axes (Y and Z) to the velocity, so the velocity will always go to the Y and Z direction.
linearVelocity.VectorVelocity = otherCharacter.HumanoidRootPart.CFrame.LookVector + Vector3.new(0, 100, -100)

instead, like Planet said above, you should be multiplying the lookvector, so the velocity is increased by 100.

linearVelocity.VectorVelocity = otherCharacter.HumanoidRootPart.CFrame.LookVector * 100

see if that works!

2 Likes

The only problem with this is that it will only go forwards but not up. Instead I decided to do this after reading your response:


			local linearVelocity = Instance.new("LinearVelocity", character:FindFirstChild("HumanoidRootPart"))
			local attachment = Instance.new("Attachment")
			attachment.Parent = character:FindFirstChild("HumanoidRootPart")
			linearVelocity.Attachment0 = attachment
			linearVelocity.MaxForce = math.huge
			linearVelocity.VectorVelocity = otherCharacter.HumanoidRootPart.CFrame.LookVector * -60
			
			local linearVelocity2 = Instance.new("LinearVelocity", character:FindFirstChild("HumanoidRootPart"))
			local attachment2 = Instance.new("Attachment")
			attachment2.Parent = character:FindFirstChild("HumanoidRootPart")
			linearVelocity2.Attachment0 = attachment
			linearVelocity2.MaxForce = math.huge
			linearVelocity2.VectorVelocity = otherCharacter.HumanoidRootPart.CFrame.UpVector * 40

I created two Linearvelocitys one on the upwards vector and one on the look vector. It works perfectly.

if you want the upwards velocity to be applied straight upwards, you can also just add + Vector3.new(0,40,0)

linearVelocity.VectorVelocity = otherCharacter.HumanoidRootPart.CFrame.LookVector * 100 + Vector3.new(0, 40, 0)

1 Like

Sweet that’s much more optimized then creating a whole new Linear Velocity. Cheers for helping me out :call_me_hand:.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.