trying to make some explosive that explodes if it hits something hard enough or something hits its hard enough
i currently have this
local HasExploded = false
local ExplosionV = 3300
local MultiplyMass = true
function Explode()
HasExploded = true
local Explosion = Instance.new("Explosion")
Explosion.Parent = workspace
Explosion.Position = script.Parent.Position
script.Parent:Destroy()
end
function CheckVelo(Velocity, Mass)
local X = Velocity.X
local Y = Velocity.Y
local Z = Velocity.Z
local Check
if MultiplyMass then
Check = (X * Mass) > ExplosionV or (Y * Mass) > ExplosionV or (Z * Mass) > ExplosionV
if Y * Mass > 1000 then print(Y*Mass) end
else
Check = X > ExplosionV or Y > ExplosionV or Z > ExplosionV
end
return Check
end
script.Parent.Touched:Connect(function(TouchedPart)
local Velocity = script.Parent.AssemblyLinearVelocity
local Velocity2 = if TouchedPart:IsA("Part") then TouchedPart.AssemblyLinearVelocity else Velocity
local V1Check = CheckVelo(Velocity, script.Parent.Mass)
local V2Check = CheckVelo(Velocity2, TouchedPart.Mass)
if V1Check or V2Check then
if not HasExploded then Explode() end
end
end)
i dont think this is going to work on smaller parts
also if a bigger part hits a small part it should require less force to explode it
1 Like
Found a decent method, works pretty nice imo
local HasExploded = false
local MinVelocity = 10
local Explosive = 300
local SelfMass = script.Parent.Mass
local TntHumanoid = script.Parent.TntHumanoid
local TNTstate
function ChangeState(Num)
end
function Explode()
HasExploded = true
local Explosion = Instance.new("Explosion")
Explosion.Parent = workspace
Explosion.Position = script.Parent.Position
script.Parent:Destroy()
end
function TakeDamage(Num)
TntHumanoid:TakeDamage(TntHumanoid)
end
function Damaged()
local Health = TntHumanoid.Health
end
function Hit(Velocity)
local Resistance = SelfMass/5 * Explosive
local X = if Velocity.X > MinVelocity then Velocity.X else 0
local Y = if Velocity.Y > MinVelocity then Velocity.Y else 0
local Z = if Velocity.Z > MinVelocity then Velocity.Z else 0
local Damage = (X+Y+Z) * SelfMass
if Damage > Resistance then
TakeDamage((Damage - Resistance)/10)
end
end
function GotHit(Velocity, Mass)
local Resistance = SelfMass/5 * Explosive
local X = if Velocity.X > MinVelocity then Velocity.X else 0
local Y = if Velocity.Y > MinVelocity then Velocity.Y else 0
local Z = if Velocity.Z > MinVelocity then Velocity.Z else 0
local Damage = (X+Y+Z) * Mass
if Damage > Resistance then
TakeDamage((Damage - Resistance)/10)
end
end
script.Parent.Touched:Connect(function(TouchedPart)
local Velocity = script.Parent.AssemblyLinearVelocity
local Velocity2 = if TouchedPart:IsA("Part") then TouchedPart.AssemblyLinearVelocity else Velocity
if Velocity.X > MinVelocity or Velocity.Y > MinVelocity or Velocity.Z > MinVelocity then
Hit(Velocity)
end
if Velocity2.X > MinVelocity or Velocity2.Y > MinVelocity or Velocity.Z > MinVelocity then
GotHit(Velocity2, TouchedPart.Mass)
end
end)
TntHumanoid:GetPropertyChangedSignal("Health"):Connect(function() Damaged() end)
3 Likes