How would I make a player get flung forward after getting hit?

So I want to make it so when a player gets hit by a car, they get flung forward a bit, and sit down. I got the sitting thing done but how would I fling them forward?

3 Likes

with a “BodyThrust” or a “BodyForce” or a “BodyVelocity” and you could use CFrame

Doing that is quite simple, and there’s several methods you could use for flinging.
(I am assuming you car has a hitbox, if not, you could replace the hitbox in the code examples with another part)

  1. Applying velocity onto the character relative to the car’s hitbox’s LookVector:
local RootPart = Character:FindFirstChild("HumanoidRootPart")
----using humanoidrootpart in order to keep this compatible with both r6 and r15
if RootPart then
   RootPart.Velocity = Hitbox.CFrame.LookVector * 25 --this number determines the fling force
end
  1. Adding the car’s velocity onto the player’s character: (more specifically, the Hitbox’s velocity onto the RootPart)
local RootPart = Character:FindFirstChild("HumanoidRootPart")
if RootPart then
   RootPart.Velocity = RootPart.Velocity + Hitbox.Velocity
end
  1. Similarly to what @NACER_RPG said, you could use BodyMovers like BodyForce and BodyVelocity aswell, but they might be more tricky to work with (since you’ll will have to set properties like MaxTorque and Force, not forgetting that you might need to destroy the BodyMover once you no longer need it).

Ah, you can also check the developer api if you want more information about BodyMovers (among other things too!).

Anyway, I hope this post helped with your issue!

1 Like