C_Sharper
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 6405 |
|
|
| 24 Mar 2017 02:47 PM |
So, I was thinking about remaking my NPC's to hopefully bring up performance of my game by a good amount.
The scripts right now, and the system overall, is a bit messy. I need to clean it up.
Just had a few questions. I'm probably gonna include a while loop to be the controller for each NPC, and this script will be located in every NPC.
Also, how frequently should I run a function to iterate through the possible targets for the NPC to see if it's current target is longer-distanced than the other targets in-game. (Automatically retarget shorter-distanced targets)
Just need to get some ideas on how to make a nice, clean, npc script going.
Thanks! |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2017 02:49 PM |
instead of controlling every npc at the same exact time, control them at different times like this
local npc = 1 game:GetService( "RunService" ).Heartbeat:connect( function() doStuffFor( npcs[ npc ] ) npc = (npc % #npcs + 1) end) |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2017 02:50 PM |
| shouldnt be putting a large amount of scripts for each npc, should be one main script controlling all npcs |
|
|
| Report Abuse |
|
|
C_Sharper
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 6405 |
|
|
| 24 Mar 2017 02:50 PM |
Are you suggesting I use a master script to control every NPC in the game, instead of a script for each npc??
It's a possible idea, definitely. Thanks |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2017 02:51 PM |
yes because you are running multiple things at the same time and it uses up your cores and causes lag etc but with one main script you run everything in order instead of all together so it causes less lag |
|
|
| Report Abuse |
|
|
C_Sharper
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 6405 |
|
|
| 24 Mar 2017 02:52 PM |
The enemies are cloned via the game script, instead of constantly running a for loop, I could insert the cloned enemies to the table using ChildAdded, and then update the index every time Heartbeat runs. This seem like a good call? Thanks, your info is very helpful.
By the way, would you think doing this would increase the performance of this game by an appreciable amount? Right now when you fight the boss, his attacks arguably lag a lot. ;/ |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2017 02:54 PM |
| you could do that or just call getChildren whenever it reaches the end of npcs |
|
|
| Report Abuse |
|
|
C_Sharper
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 6405 |
|
|
| 24 Mar 2017 02:54 PM |
| Sweet. Thanks man. I will surely do this! Shouldn't be that hard at all. |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2017 02:55 PM |
and if his attacks are lagging then there is something in the attack scripts that are lagging
also roblox pathfinding may lag sometimes too, on my self driving npc car game, when it hits a certain spot in the terrain it causes gigantic lag spikes for seemingly no reason |
|
|
| Report Abuse |
|
|
C_Sharper
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 6405 |
|
|
| 24 Mar 2017 02:57 PM |
That's exactly why I'm ditching PFS. Its not even that effective.
Btw, in each npc there is the animator script. This would sort of be hard to handle from a single script, would that be a loss of performance? |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2017 03:01 PM |
you can just do this
local animations = {}
--run when npcs inserted animations[ npc ] = { walk = --load anim walk; run = --load anim run; slash = --load anim slash; }
local anims = animations[ npc ] anims.walk:Play() |
|
|
| Report Abuse |
|
|
C_Sharper
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 6405 |
|
| |
|
|
| 24 Mar 2017 03:12 PM |
Using 1 main script for each NPC will cause huge amounts of lag if you plan on actually doing something with the NPC. Inserting the script into each NPC i have found works better performance wise.
Reason I say this is because something simple as for looping the touched event for around 20 to 30 bricks in your games does cause a lot of lag for me, but however if I put the touched event into each individual script it works a tad faster. |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2017 03:17 PM |
that doesnt matter he is talking about running something constantly for all npcs and running multiple things at the same time will be far more laggy than running for each npc at 60 fps, so wrong |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2017 03:33 PM |
| Yeah problem with your technique is that hes gonna make all the NPC's do the same thing unless he codes it individually for each NPC, just put a script in each one, its much easier and probably will not cause big performance drop. Its how most games do it |
|
|
| Report Abuse |
|
|
C_Sharper
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 6405 |
|
|
| 24 Mar 2017 03:40 PM |
this thread is confusing me
which way is better /; |
|
|
| Report Abuse |
|
|
|
| 26 Mar 2017 12:45 PM |
| hes wrong, instead of running it for each npc per frame he wants to constantly run code at the same exact time for each ai which is much more laggy trust me |
|
|
| Report Abuse |
|
|
C_Sharper
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 6405 |
|
|
| 26 Mar 2017 01:00 PM |
| It does make sense Wunder. Just hope I see performance improvement for doing this conversion, but however, using this method is much cleaner and easier to edit the bot stats. |
|
|
| Report Abuse |
|
|