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.
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?
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:
Set BlastPressure to zero
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
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
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().
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.
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).
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