BodyForce shockwave help

Hey Developers,

How do I make a sendback effect like from a certain point? Where depending on the players position relevant to a certain area, they get sent back reletive to that area. For an example of what I mean, use this image as a reference:

The green is where the player gets sent to if I tween it,
The Blue is the point at which the shockwave comes from,
and the red is where I want them to go,
and the pink is where the player starts.


Notice how the red goes away from the blue point no matter where they are? How can I acheive this effect where the player always gets sent away from the blue point?

2 Likes

Use BodyPosition to achieve this.

local BP = Instance.new("BodyPosition")
local Player = --Get the player in some way, I don't know how you want to do that
local Char = Player.Char
local HumRootPart = Char.HumanoidRootPart

BP.MaxForce = Vector3.new(4000, 4000, 4000) -- Will exert a force of 4000 on any axis.
BP.P = 1000 -- This is the power of the BP, this will measure the aggressiveness of the pushing (i.e. the speed)
BP.D = 500 -- This is dampening, basically kinda like a cushion effect to dampen the power.
BP.Position = (HumRootPart.CFrame * CFrame.new(0,0,10)).p -- This will set them 10 studs backwards from their current position, edit the '10' depending on how far back you want them to go
wait(5)
BP:Destroy() -- There are probably better ways to get rid of it properly
1 Like
local BP = Instance.new("BodyPosition")
local Player = game.Players.LocalPlayer
local Char = Player.Character
local HumRootPart = Char:WaitForChild("HumanoidRootPart")

wait(4)

BP.MaxForce = Vector3.new(4000, 4000, 4000) -- Will exert a force of 4000 on any axis.
BP.P = 1000 -- This is the power of the BP, this will measure the aggressiveness of the pushing (i.e. the speed)
BP.D = 500 -- This is dampening, basically kinda like a cushion effect to dampen the power.
BP.Position = (HumRootPart.CFrame * CFrame.new(0,0,10)).p -- This will set them 10 studs backwards from their current position, edit the '10' depending on how far back you want them to go
wait(5)
BP:Destroy() -- There are probably better ways to get rid of it properly

Im using that but its not working. Whats wrong?

game.Players.LocalPlayer can only be called from a local script. You will want this in a server script which will allow other players to see the player be flung back.

I suggest reading up on RemoteEvents, and creating a system that detects if the player is too close to that blue spot.

Still not working!

Client Script:

wait(5)

game.ReplicatedStorage.RemoteEvent:FireServer(game.Players.LocalPlayer)

Server Script:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Plr)
	
	local BP = Instance.new("BodyPosition")
	local Player = Plr
	local Char = Player.Character
	local HumRootPart = Char:WaitForChild("HumanoidRootPart")

	BP.MaxForce = Vector3.new(4000, 4000, 4000) -- Will exert a force of 4000 on any axis.
	BP.P = 1000 -- This is the power of the BP, this will measure the aggressiveness of the pushing (i.e. the speed)
	BP.D = 500 -- This is dampening, basically kinda like a cushion effect to dampen the power.
	BP.Position = (HumRootPart.CFrame * CFrame.new(0,0,10)).p -- This will set them 10 studs backwards from their current position, edit the '10' depending on how far back you want them to go
	print("HAH")
	wait(5)
	BP:Destroy() -- There are probably better ways to get rid of it properly
	
end)

Are there any errors in the console?

No errors in the console, so nope.

Does it print what you told it to print?

Yes.

I hate the character limit.

Try this function

function pushChar(charToPush, pushPoint: Vector3)
	local HRP = charToPush.HumanoidRootPart
	local dir = ((HRP.Position - pushPoint) * Vector3.new(1, 0, 1)).unit --direction to push them in
	local pushForce = 100 --Force character is being pushed at
	local pushDuration = 0.2 --Amount of time the force is applied
	
	local BV = Instance.new("BodyVelocity")
	BV.MaxForce = Vector3.new(math.huge, 0, math.huge)
	BV.Velocity = dir * pushForce
	BV.Parent = HRP
	
	game:GetService("Debris"):AddItem(BV, pushDuration)
end

Thanks, it works! However, how do I make the player also float upwards if the explosion point is below them?

function pushChar(charToPush, pushPoint: Vector3)
	local HRP = charToPush.HumanoidRootPart
	local dir = (HRP.Position - pushPoint).unit --direction to push them in
	local pushForce = 100 --Force character is being pushed at
	local pushDuration = 0.2 --Amount of time the force is applied
	
	local BV = Instance.new("BodyVelocity")
	BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	BV.Velocity = dir * pushForce
	BV.Parent = HRP
	
	game:GetService("Debris"):AddItem(BV, pushDuration)
end

Thanks! And now finally, how can I make the player slow down and eventually stop? (Without ending up falling down)

Falling down like from a height or is your character tripping?

Falling down from a height. I want it to explode out and then the player slows down and eventually stops without falling down

I dont think I understand. You want them to be pushed into the air but not fall down?

yes. They get pushed away from the shockwave, however eventually they slow down then stop. and they DONT fall back to the ground.

Do you want to know how to get a force that is pointing away from a specific position like this?

so you want them stay floating?

Yes! kojo crashed already acheived this, however its not exactly how I want it (yet)