--Velocity is a variable predetermined in earlier parts of this script. --Velocity is a vector3 if Target.Character.Torso:FindFirstChild("BV") == nil then BV = Instance.new("BodyVelocity") BV.Name = "BV" BV.Parent = Target.Character.Torso end Target.leaderstats.LastHit.Value = Player.Name Target.Character.Torso.BV.MaxForce = Vector3.new(10000,1000000,0) Target.Character.Torso.BV.Velocity = Velocity wait(0.0001) Target.Character.Torso.BV:Destroy()
So, above is a part of my code that makes knockback. I initially just wanted to change the velocity property. It works fine on dummys, but not on players' characters.
I am now forced to use body velocities for characters but there is one problem.
The purpose of each is completely different.
Velocity property adds a burst of force, and lets the physics engine naturally slow the object down.
Body velocity is meant to apply constant velocity.
I tried to replicate that burst of energy by destroying the body velocity in a really short time frame.
The problem with this is the lag. Sometimes, if the velocity is changed quick enough, it works, but it is a little rough. Most of the time, nothing happens because the body velocity is destroyed
When i change the wait time to 0.1, the big knockback looks good, but short knockback is increased due to the amount of time the body velocity has to push.
How can I do a short burst kinda like altering the velocity property with a body velocity?
I recommend a BodyForce to do this. You can also use the Debris service instead of having a wait timer before deleting it, it will schedule the removal of the object without yielding any code.
if not Target.Character.Torso:FindFirstChild('BF') then local BF = Instance.new('BodyForce') BF.Name = 'BF' end Target.leaderstats.LastHit.Value = Player.Name BF.force = Velocity BF.Parent = Target.Character.Torso game:GetService('Debris'):AddItem(BF, .3) --BF will be removed in .3 seconds
I recommend you put the Velocity variable to something like Vector3.new(10000,10000,0).