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?
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
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
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.
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)
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
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