How to get knock a player back

So basically i have a projectile, and i want to make it so when the projectile hits the player, they are knocked back.

I was going to use a BodyVelocity, the problem is i don’t know how to get the opposite side of the hit.

So what i can’t do is get the opposite side the projectile hit the player.

Any help is appreciated and if it wasn’t understandable you can ask me to explain it better. Thanks!

1 Like

You could try making a ray from the player that fired the projectile to the player that was hit, then get the direction, convert the direction to a unit vector, like this

local ray = workspace:Raycast(Player1.Tool.Handle.Position , script.Parent.Position)
TouchedPart:ApplyImpulse(ray.Direction.Unit * 500)

This assumes that the projectile is a part and that this script ia parented to the part.

1 Like

I have a part that will touch the hit player, so i think it would be easier to make something off the part that is hitting them.

local Force = -250
BodyVelocity.Velocity = TargetCharacter.HumanoidRootPart.CFrame.LookVector * Force

CFrames usually have a LookVector property, which basically takes the current direction where that specific part (HumanoidRootPart) is looking at

If you multiply that with a negative force, the Target’s Character would be pushed back

1 Like

yes, this could run in a touched event.

Will test those out, brb :smiley:

Yes but @Faczki remember to destroy the bullet right after it touches the player or add a debounce so you can avoid any kind of repeated actions :slight_smile:

1 Like

Yes! I will not forget to destroy it, thanks for the reminder

1 Like

It is working but very weakly, what i mean is the player is not being pushed very far, i even tried puttin force in -2500 and it is still weak.

Have you tried setting the MaxForce property to math.huge?

BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)

ADDITIONALLY, you can use the Debris:AddItem() function so that you don’t have to worry about destroying it later on

local Force = -50 --We don't want to make this literally send the Player to Brazil

BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BodyVelocity.Velocity = TargetCharacter.HumanoidRootPart.CFrame.LookVector * Force
game.Debris:AddItem(BodyVelocity, 1)
5 Likes