Below is the code that simulates a projectile shout out a canon. This canon preforms fine when the SGSPhysicSolver is disabled. However, I would like to utilize the PhysicSolver in my game. Any advice on changes I could try?
Cannon-
function Fire(t)
t.Gun.FireSound:Play()
t.Gun.Fire:Emit(20)
t.Gun.Smoke:Emit(20)
t.Gun.Muzzle.Enabled = true
delay(0.1,function() t.Gun.Muzzle.Enabled = false end)
FastSpawn(function()
for i = 1,5 do
t.FBarrel.Weld.C0 = t.FBarrel.Weld.C0*CFrame.new(0,0,-0.8)
wait()
end
for i = 1,20 do
t.FBarrel.Weld.C0 = t.FBarrel.Weld.C0*CFrame.new(0,0,0.2)
wait()
end
end)
local shell = sp.Shell:clone()
shell.Parent = workspace
shell.Core.Weld:Destroy()
shell.Core.Fire.Enabled = true
shell.Core.Smoke.Enabled = true
shell.Shell.Transparency = 0
shell.Core.CFrame = t.Gun.CFrame * CFrame.new (0,0,2.2)
shell.Core.Velocity = t.Gun.CFrame.lookVector * set.ShellSpeed
shell.Core.CFrame = shell.Core.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(-90),math.rad(180))
game:GetService("Debris"):AddItem(shell,set.ShellDuration)
local gravity = Instance.new("BodyForce", shell.Core)
for i,v in pairs (shell:GetChildren()) do
gravity.force = Vector3.new(0, gravity.force.Y + v:GetMass() * set.ShellGravity, 0)
end
local touched = false
shell.Core.Touched:connect(function(part)
if part.Parent ~= sp and part.Parent ~= t then
if touched == false then
touched = true
Explode(shell.Core.Position)
DamageVehicle(part)
for _,plr in pairs(game.Players:GetPlayers()) do
if plr:DistanceFromCharacter(shell.Core.Position) <= set.ExplosionRadius and plr.TeamColor ~= sp.Team.Value then
plr.Character.Humanoid:TakeDamage(set.Damage)
wait()
end
end
shell:Destroy()
end
end
end)
end
Settings-
local set = {
ExplosionRadius = 8; --Radius of the explosion
ShellDuration = 10; --Duration of the shell (cleanup purposes)
Damage = 100; --Damage of explosion
ShotCooldown = 1.8; --Single shot cooldown
ShellSpeed = 600; --Velocity of the shell
CannonRotate = 0.25; --Increment of the barrel rotation up/down
PlatformRotate = 0.75; --Increment of the turret rotation left/right
CRMaxPos = 30; --Maximum upwards rotation of the barrel -- RADIANS
CRMaxNeg = 15; --Minimum downwards rotation of the barrel -- RADIANS
RepairTime = 300;
Health = 1000;
SidMaxRot = 150; --Maximum sideway rotation of the turret --RADIANS
ShellGravity = 180; --Gravity of the shell, 196.2 is ZERO GRAVITY
}
return set
