Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can a body velocity replicate the velocity property?

Asked by 6 years ago
--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?

0
You could gradually decrease the force, then destroy it. hiimgoodpack 2009 — 6y
0
Since the server does not calculate the players physics you might want to test this by setting it on the client side. User#5423 17 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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

0
Oh, the Velocity Variable is actually pre calculated velocity based on some factors for the knockback. Imma try using body force and comment back if it was a success. User#17125 0 — 6y
0
It doesn't move the character at all. Im assuming this is because the velocity variable is meant to be a velocity, not a force User#17125 0 — 6y
Ad

Answer this question