How to make player not affected by explosion?

I want an explosion not to affect the player. The player doesn’t get killed by the explosion because:

explo = Instance.new("Explosion")
explo.DestroyJointRadiusPercent = 0

The only problem left is that the player gets thrown away. I don’t want to do

explo.BlastPressure = 0 

because then the explosion does nothing to the other objects.

4 Likes

You can anchor the player, but that wont work if you still want the player to move during the explosion.

1 Like

I was thinking maybe you can check for a change in velocity on the root part once the force is applied and quickly subtract the force to counteract the explosion force.

You can try adding a bodyforce into the player’s HumanoidRootPart with downward force. This would (basically) act like extra gravity and help keep the player on the ground.

2 Likes

But is there a way to make the explosion completely ignore the player just like in Destruction Simulator, where the explosions completely ignore the player?

2 Likes

I haven’t played it, but it sounds like they made custom explosions and not the default roblox ones.

2 Likes

They probably set the BlastPressure to zero and programmed a custom behavior using Explosion.Hit. Using BodyMovers or constraints, or otherwise editing the velocities directly, is likely to be pretty janky.

using what @suremark said i came up with a solution:

  1. Set BlastPressure to zero

  2. Get the part from explosion.Hit, and then get the vector offset from the source of the explosion to the part’s position. Make sure the part is not part of a player. You can do this with this function:

local function isPlayer(part)
    return part:FindFirstAncestorWhichIsA("Player")
    -- this returns false if it's not from a player, or the player if it is from a player.
end
  1. Use that magnitude of that vector offset (the magnitude distance) to calculate the new BlastPressure that you’re going to use for your custom explosion. You can use the following lerp function for this:
function lerp(a, b, c)
    return a + ((b - a) * c)
end
  1. The vector offset can now be used to calculate the direction that the part has to continue in. Think of this as the direction portion (the second parameter) of Ray.new().

  2. Get the .Unit of that vector offset and multiply it by the custom BlastPressure that you calculated before. Then apply that new velocity to the part.

You can also add custom particle effects and stuff since it’s a custom explosion.

1 Like

How do I get the vector offset of the source of the explosion?

(explosion.Position - hit.Position)
note: hit is the part that you got from explosion.Hit:Connect()

Okay, I’ll try it. Or would there just be a easier method to give parts a velocity in the direction the player is facing? Since I actually want to make the player punch and if that punch hits an object it gets thrown away. I have everything set up and the only thing missing is the velocity (which i tried by adding in a explosion in the players hand, but now the player flies away too).

I’m pretty sure that it’s the easiest way. This is what’s normally used when casting a ray as well.

1 Like

Okay, I’ll try to look up how to add velocity to something using rays.

2 Likes

Okay, since what’s being talked about now, I’ll create a new topic.

2 Likes

This is very old, but I would still like to leave this contribution for those who have the same problem

local explo = Instance.new(“Explosion”)
explo.Position = Vector3.new(0,5,0)
explo.DestroyJointRadiusPercent = 0
explo.BlastPressure = 0

explo.Hit:Connect(function(hit, distance)
local playerPart = game.Players:GetPlayerFromCharacter(hit.Parent)
if playerPart then

  print("The player is in the zone but will not be affected.")

elseif not hit.Parent:IsA(‘Accessory’) then

  local offset = explo.Position - hit.Position
  local direction = offset.Unit  
  local customPressure = 500     

  local bodyVelocity = Instance.new("BodyVelocity")
  bodyVelocity.Velocity = direction * customPressure
  bodyVelocity.Parent = hit

end
end)

explo.Parent = game.Workspace

2 Likes

wondering if we could use collision groups