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)
- 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
- Adding the car’s velocity onto the player’s character: (more specifically, the
Hitbox
’s velocity onto theRootPart
)
local RootPart = Character:FindFirstChild("HumanoidRootPart")
if RootPart then
RootPart.Velocity = RootPart.Velocity + Hitbox.Velocity
end
- Similarly to what @NACER_RPG said, you could use
BodyMovers
likeBodyForce
andBodyVelocity
aswell, but they might be more tricky to work with (since you’ll will have to set properties likeMaxTorque
andForce
, not forgetting that you might need to destroy theBodyMover
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