How do I code force

By force I mean like, if I were to code somebody getting hit by a car, how would I add force on a player to send them flying? And how would I put it in the direction I want?

You can use the AddForce() method of a player’s HumanoidRootPart

-- Get the player and their HumanoidRootPart
local player = game.Players.LocalPlayer
local humanoidRootPart = player.Character.HumanoidRootPart

-- Set the force vector in the direction you want
local forceDirection = Vector3.new(0, 100, 0)

-- Add the force to the player's HumanoidRootPart
humanoidRootPart:AddForce(forceDirection)

You can change the values of the vector to adjust the direction and magnitude of the force.

2 Likes

you can use velocity or addforce
but here’s the velocity method

“getting hit by the car”

script.Parent.Touched:Connect(function(hit)
   if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent:FindFirstChild("HumanoidRootPart").Velocity = workspace.Car.CFrame.LookVector * 100
   end
end)

.Velocity is deprecated, consider using LinearVelocity instance

I think Impulse will suit your task the best.

These methods literally don’t exist. You need to use ApplyImpulse instead.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.