Is this an efficient way to handle bullet travel on the server?
Using raycasting every frame on the server, I'm aware this completely ignores the size of the bullet. If I wanted to incorporate that would it be wise to just unanchor the bullet and use velocity with a touch listener?
Or I could incorporate EgoMoose's Region3 module.
Any ideas?
03 | function Class:Launch(origin, whitelist) |
05 | local raycastParams = RaycastParams.new() |
06 | raycastParams.FilterDescendantsInstances = whitelist or { } |
07 | raycastParams.FilterType = Enum.RaycastFilterType.Blacklist |
08 | raycastParams.IgnoreWater = true |
12 | while tick() < start + self.Lifetime and not result do |
13 | local step = RunService.Stepped:Wait() |
14 | local gravity = (workspace.Gravity / 196.2 ) * 9.807 |
15 | local drop = (gravity / 2 ) * math.pow(step, 2 ) |
17 | yVelocity = (yVelocity + drop) |
18 | local target = (origin * CFrame.new( 0 , 0 , -self.Speed * step)) - Vector 3. new( 0 , yVelocity, 0 ) |
19 | local rayResult = workspace:Raycast(origin.Position, (target.Position - origin.Position).Unit * (self.Speed * step), raycastParams) |
22 | self.Projectile.CFrame = CFrame.new(rayResult.Position, target.Position) |
23 | if rayResult.Instance then |
27 | self.Projectile.CFrame = CFrame.new(target.Position, origin.Position) * CFrame.Angles( 0 , math.rad( 180 ), 0 ) |
33 | print ( "Projectile took" , tick() -start, "seconds" ) |
37 | local surface = self:GetSurface(result) |