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)
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
“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.