I have some SWEPs made that are about throwing watermelons, but the code for applying force is very confusing. Does anybody know an easy to understand code that I can use and change if I need to. Here is my code for SWEP:throw_attack.
function SWEP:throw_attack (model_file) local tr = self.Owner:GetEyeTrace() self:EmitSound(ShootSound) self.BaseClass.ShootEffects(self) if (!SERVER) then return end local ent = ents.Create("prop_physics") ent:SetModel(model_file) ent:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 16)) ent:SetAngles(self.Owner:EyeAngles()) ent:Spawn() local phys = ent:GetPhysicsObject() if !(phys && IsValid(phys)) then ent:Remove() return end //this is what I need help with phys:SetVelocity(self.Owner:GetForward() * 500000 + Vector(5000,0,0)) cleanup.Add(self.Owner, "props", ent) undo.Create ("Thrown_SWEP_Entity") undo.AddEntity (ent) undo.SetPlayer (self.Owner) undo.Finish() end
The original code I had for force was:
phys:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized() * math.pow(tr.HitPos:Length(), 3))
Both codes are confusing and don’t work the way I want them to no matter how much I try to adjust them.