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

How Would I Go About Pushing The Player The Opposite Direction That They Are Looking?

Asked by 4 years ago

I Am Working On A Game Where When Players Knock Into Each Other, They Are Pushed Back In The Opposite Direction The Torso Is Facing. I Have Written Some Code To Do This, But It Is Not Working As Intended,

local player = game.Players.LocalPlayer

local Body = script.Parent:WaitForChild("Torso")

local Humanoid = script.Parent:WaitForChild("Humanoid")


Humanoid.Touched:Connect(function(HitBody)
    if HitBody.Name == "Torso" then
        print("Launch")
        Body.Velocity = Vector3.new(Body.Position.X / Body.Position.X * HitBody.Size.X * -1, 0, Body.Position.Z / Body.Position.Z * HitBody.Size.Z * -1)
    end
end)

1 answer

Log in to vote
0
Answered by
zadobyte 692 Moderation Voter
4 years ago

You should create a new BodyVelocity instance. After you do that, do:

local bodyVel = Instance.new("BodyVelocity")

bodyVel.Velocity = character.CFrame.LookVector
bodyVel.MaxForce = Vector3.new() * math.huge
bodyVel.Parent = character.PrimaryPart
--note: intentional errors in given code
0
Thank You So Much! overwatcher54 11 — 4y
Ad

Answer this question