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

How to make knockback script? BodyVelocity not working well

Asked by 4 years ago

Hello everyone! I've been working on a fighting game for some time, similar to Super Smash Bros.. If you've played the game, you would know that players are knocked back when hit, following a parabolic trajectory. How can I make the player follow a parabola? I've used CFrame but it's too choppy, and I've tried BodyVelocity and it's pretty slow (the player gains velocity exponentially instead of max upon impact). Any help would be appreciated. Thank you!

1 answer

Log in to vote
1
Answered by
ryan32t 306 Moderation Voter
4 years ago
Edited 4 years ago

I would still recommend BodyVelocity. I made a Telekinesis Script for someone a couple days ago and I used Body Velocity.

Here would be an example of the Telekinesis Script but instead of Telekinesis.. We're knocking the targeted player backwards 10-20 studs in the direction of the Original Player's HumanoidRootPart Front Face.

-- Local Script: Child of StarterGui, Parent of RemotEvent, Ancestor of Script

local plr = game.Players.LocalPlayer
repeat wait() until plr.Character and plr.Character.HumanoidRootPart
local char = plr.Character
local hpart = char.HumanoidRootPart
local mouse = plr:GetMouse()
mouse.TargetFilter = char
local remoteEvent = script.RemoteEvent

mouse.Button1Down:Connect(function()
    if mouse.Target then
        if mouse.Target.Parent:IsA("Model") then
            if mouse.Target.Parent:FindFirstChild("Humanoid") then
                local target = mouse.Target.Parent.HumanoidRootPart
                remoteEvent:FireServer(hpart.CFrame.LookVector,target)
            end
        end
    end
end)
-- Server Script: Child of RemoteEvent, Descendant of Local Script

local remoteEvent = script.Parent

remoteEvent.OnServerEvent:Connect(function(plr,direction,target)
    local bodyV = Instance.new("BodyVelocity")
    bodyV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
    bodyV.Parent = target
    bodyV.Velocity = direction*150
    wait(0.1)
    bodyV.Velocity = Vector3.new(0,0,0)
    wait()
    bodyV:Destroy()
end)
Ad

Answer this question