Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

1 comment

0

Thank You So Much!

This discussion is preserved as it was. New answers, comments, and votes are closed.