# How do I convert a BodyVelocity into a tween/lerp?

Hey,
I have a script that applies ‘knockback’ to a target when they are hit. The knockback moves the player 2.5 studs up and an undefined horizontal
See below:

Script Segment
``````local VerticalKB = Instance.new("BodyVelocity")
VerticalKB.Parent = targetTorso
VerticalKB.MaxForce = Vector3.new(TotalForce,TotalForce,TotalForce)
VerticalKB.Velocity = attackerTorso.CFrame.LookVector * HorizontalKB + Vector3.new(0,25,0) -- HorizontalKB is an integer (so any number will do)
``````

The script works perfectly fine.
However, BodyVelocities are very inconsistent and can be easily manipulated.
How do I go about making the script above a tween/lerp?
Edit: The time for the tween/lerp would be .1 seconds (also when the velocity gets destroyed)

Velocity is measured in SPS, so you will need to find out how long your velocity is active and how fast it is.

Yeah, I forgot to mention that the time would be .1 seconds

You could try changing the AssemblyLinearVelocity of the target’s HumanoidRootPart

``````local MoveVector = CFrame.new(KillerTorso.Position, TargetTorso.Position).LookVector
Target.HumanoidRootPart.AssemblyLinearVelocity += MoveVector * 2 --Experiment with this multiplier
``````

So, your tween should knockback “(HorizontalKB plus (0, 25, 0)) times 0.1” in studs.

“HorizontalKB” is the distance the player is pushed backwards, and the (0, 25, 0) is the VerticalKB or how far up the player goes up. The 0.1 is how long the velocity is applied to the player before it gets deleted.

Look, I’m telling you how to calculate the position of the tween. I’m not going to do the tween for you or anything, because I assume you know how to do so.

You have all the information you need. The tween is basically the same as the BodyVelocity but is multiplied by the time until it gets destroyed.

I understand, I’m just clarifying because it seemed like you were confused.

1 Like