Cinnace
|
  |
| Joined: 21 Jun 2016 |
| Total Posts: 370 |
|
|
| 04 Jul 2016 02:25 PM |
like, not a laser beam, just a ray. I'll have ray tracing disabled.
I'm currently doing a bullet drop like this
repeat loops = loops + 1 local ray = Ray.new(source,Direction * velocity) local h,pos = game.Workspace:FindPartOnRayWithIgnoreList(ray,{game.Players.LocalPlayer.Character,game.Workspace.BulletDump,hitIgnore}) hit = h table.insert(rays,ray) source = pos Direction = Direction + Vector3.new(0,-.01,0) until hit or loops >= 100
- Cinnace |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 04 Jul 2016 02:30 PM |
Depends... ur way is a bit innefficient, in a loop u should aim for efficiency as a VERY big priority if u plan on using that loop a few times and/or if the loop lasts long. Change table.insert to rays[#rays + 1] = ray and ad a wait() are my suggestions to improve it. |
|
|
| Report Abuse |
|
|
Cinnace
|
  |
| Joined: 21 Jun 2016 |
| Total Posts: 370 |
|
|
| 04 Jul 2016 02:31 PM |
I'm going to add a wait() to simulate bullet delay
- Cinnace |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 04 Jul 2016 02:37 PM |
Ah k, also, if I were u, I'd remove the source = pos and hit = h just remove the local when using FindPartOnRay() and then just compare until h or loops == 100 and instead of doing things like source = pos just set the 2nd returned value as 'source' :P |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 04 Jul 2016 02:40 PM |
| If u want proof that what am saying will improve ur script performance then go ahead, try ur script and open up script performance tab, and see the % then try modify ur code with my suggestions and u'll see the % is gonna be lower (Which is a good thing) :) |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 02:41 PM |
for i = 1, 100 do local ray = Ray.new(source,Direction * velocity) local hit,source = game.Workspace:FindPartOnRayWithIgnoreList(ray,{game.Players.LocalPlayer.Character,game.Workspace.BulletDump,hitIgnore}) table.insert(rays,ray) Direction = Direction + Vector3.new(0,-.01,0) if hit then break end end
Improved it a little :) |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 04 Jul 2016 02:44 PM |
That could be used too, mostly due to the fact that u wont have to use an 'if' statement ('until' is similar to an 'if' statement pretty much) to keep checking per loop if the number of loops is the same as the limit, but a numerical loop isn't necessarily better in performance for 100 loops (Somewhat tested) but anyways... Btw, if u'd like, u can learn from my previous segmented raycasting module, it's free sourced (I made a newer one some time ago, so I decided to make the old one available) https://www.roblox.com/Raycast-Module-item?id=251776324 |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 02:45 PM |
| @Kap He should use a for loop because he wants the loop to end at a maximum of 100 iterations. This also makes for less checking at the end of the loop, since he only has to check 1 condition rather than 2. |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 04 Jul 2016 02:45 PM |
| war, I noticed that in ur script u made 'source' a local variable, therefore not setting it to the new position. |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 04 Jul 2016 02:46 PM |
Yeah I know, I stated that XD :P I just said that if he wasn't going to follow that path, he could look at my code :) |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 02:47 PM |
local hit,source for i = 1, 100 do local ray = Ray.new(source,Direction * velocity) hit,source = game.Workspace:FindPartOnRayWithIgnoreList(ray,{game.Players.LocalPlayer.Character,game.Workspace.BulletDump,hitIgnore}) table.insert(rays,ray) Direction = Direction + Vector3.new(0,-.01,0) if hit then break end end
Better? He didn't provide the whole code, I didn't know if he needed it outside the loop or not. |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 04 Jul 2016 02:50 PM |
| Better :) But yeah I get it, happens sometimes when ur new to something ;) (In ur case segmented raycasting) |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 02:52 PM |
I'm not new to anything here?
All I did was provide something functionally equivalent to the piece of code. He didn't provide anything about the code around it. |
|
|
| Report Abuse |
|
|
IanVIII
|
  |
| Joined: 03 Apr 2016 |
| Total Posts: 535 |
|
|
| 04 Jul 2016 02:54 PM |
I wouldn't use wait() a very bad idea.
Are you doing this on the server or the client because if you're calculating it on the client then you could use renderstepped. Then again, it would be safer to do it on the server.
I would recommend not calculating bullet wait time as it has very little effect to gameplay and players won't even notice. |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 02:56 PM |
| Why wouldn't you use wait() lol |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 04 Jul 2016 02:58 PM |
Not going against u war, just telling u that sometimes the code should be read more thoroughly XD :P Cos obviously he didn't take 'source' from his a*s XD :P
Ian, he said performance wise not how to make it instant :P Performance-wise it's worse than wait() (Suppose to be) :P |
|
|
| Report Abuse |
|
|
IanVIII
|
  |
| Joined: 03 Apr 2016 |
| Total Posts: 535 |
|
|
| 04 Jul 2016 03:00 PM |
| One of the first things I was taught whilst learning lua was not to ever use wait() as it lags the script. I've never questioned it, but after thinking about this I think it would only apply to loops. In which case, I'm being stupid: ignore me. |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 04 Jul 2016 03:00 PM |
| Lol who told u not to use wait()? |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 03:01 PM |
| @Kap I did read his code. Again, my code was functionally equivalent. He provided no context about the outter scopes. |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 03:02 PM |
Lol who told you not to use wait()[2]
wait isn't laggy lol |
|
|
| Report Abuse |
|
|
IanVIII
|
  |
| Joined: 03 Apr 2016 |
| Total Posts: 535 |
|
|
| 04 Jul 2016 03:05 PM |
I meant to use wait() without any arguments. I guess if it's used in a loop it would probably cause it to lag. |
|
|
| Report Abuse |
|
|
| |
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 04 Jul 2016 03:08 PM |
| Lol, it would actually PREVENT the code from lagging :P |
|
|
| Report Abuse |
|
|