You could override the default Jump behaviour without rewriting the whole entity.
I think it'd be cooler if instead of not jumping it jumped to the edge of the radius though.Code:local HoverDrive = scripted_ents.GetStored("gmod_wire_hoverdrivecontroller") local OldJump = HoverDrive.Jump function HoverDrive:Jump() for _, jammer in pairs(HoverdriveJammers) do if jammer:InRadius(self) then return self:FailJump() end end return OldJump(self) end
Given that the SphereHitPos is defined something like thisCode:function HoverDrive:Jump() for _, jammer in pairs(HoverdriveJammers) do if jammer:InRadius(self) then self.JumpTarget = SphereHitPos(self:GetPos(), self.JumpTarget - self:GetPos(), jammer:GetPos(), jammer:GetRadius()) end end end
Code:-- http://en.wikipedia.org/wiki/Line%E2%80%93sphere_intersection function LineSphereIntersect(l, c, r) l:Normalize() local lc = l:dot(c) local det = lc*lc - c:dot(c) + r*r if det < 0 then return elseif det == 0 then return lc else det = math.sqrt(det) return lc + det, lc - det end end function SphereHitPos(Origin, Direction, SphereCentre, SphereRadius) Direction:Normalize() local max, min = LineSphereIntersect(Direction, SphereCentre, SphereRadius) if min>max then max, min = min, max end return Origin + Direction*min end


LinkBack URL
About LinkBacks




Reply With Quote



Bookmarks