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

How could I make an object move away from another object using BodyVelocity?

Asked by
wddfrt 21
3 years ago
Edited 3 years ago

I have a script that flings your character when you die. The problem is, I want the person being killed to fly away from the direction that the killer is looking. I already know how to find who killed the person (which is why i'm looking for the killer on line 25) and how to find where the killer is looking, but i'm confused on how to make the player fling away from the killer.

local Humanoid
while not Humanoid do
    wait()
    Humanoid = script.Parent:FindFirstChildWhichIsA("Humanoid")
end


function Fling()
    if Humanoid and Humanoid.Parent then
        local attackerpos = Humanoid:FindFirstChild("killer").Character.HumanoidRootPart.CFrame.lookVector -- finding out the direction that the player is looking

        local BodyVelocity = Instance.new("BodyVelocity")
        BodyVelocity.Parent = Humanoid.Parent.UpperTorso

        BodyVelocity.Velocity = Vector3.new(0, 0, 0) --this is what i need to change

        BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
        wait(0.1)
        BodyVelocity:Destroy()
    end
end


Humanoid.Died:connect(function()
    if Humanoid:FindFirstChild("killer")then --finding the killer's player from a ObjectValue
        Fling()
    end
end)

Any help would be greatly appreciated.

2 answers

Log in to vote
0
Answered by
wddfrt 21
3 years ago

I figured it out, All I had to to was change BodyVelocity.Velocity = Vector3.new(0, 0, 0) into BodyVelocity.Velocity = AttackerPos+AttackerPos*50

Ad
Log in to vote
0
Answered by 3 years ago

You could of use CFrame to find the direction the killer was looking and add a velocity for example

BodyVelocity.Velocity = Attacker.CFrame.LookVector * 50 --Change the number to the velocity you want to be applied

Answer this question