Jump to content

Spawners will spawn even if they shouldnt


Slastraf
 Share

Recommended Posts

http://www.mediafire.com/download/dm6d64ri0476tz5/WinRARbySlastraf.rar

Above a link to my project (~40 mb)

 

In the start map there is a folder in the scene editor called spawners.

there are some spawners and a spawncontroller.

the spawners themsleves are able to spawn crawlers into the scene,

the spawncontroller is able to increase the maximum amount of enemies in the scene every new round.

 

My problem is that there are still spawning crawlers and i dont know why,

The method SpawnEnemy() in the zombiespawner script doesnt get triggered nowhere and i am very confused.

 

Thanks for reading and helping

Friedrich

 

Pm: textures are missing for small download size

Link to comment
Share on other sites

Figured it out. You loaded the prefabs of the zombies when you start the script (lines 11 and 12). So when you start the game, every spawner spawns 2 crawlers. This should be in the SpawnEnemy function so only when it called they are spawned.

I had that before, but it affects the frames very much.

When the spawnEnemy function is called, it loads it once again, even if not necessary.

Link to comment
Share on other sites

In ZombiesSawner.lua you are loading 2 zombie prefabs:

 

if self.zombie==nil then self.zombie= Prefab:Load("Prefabs/Characters/crawler1.pfb")end

if self.zombie2==nil then self.zombie2 = Prefab:Load("Prefabs/Characters/orangecrawler.pfb")end

 

You aren't setting the positions to the spawner positions so they are all spawning at 0,0,0 and running toward the turret. Because you have 6 spawners you get 12 zombies right away.

 

 

I think you are running into an issue where you need to preload 1 zombie prefab and always keep it in your scene but disable it. That way other loads will load instances of the same one which will be basically instant. If you don't have any instances of a model and then you load it during run-time it'll pause your game. If you load an instance and then kill/release them and another one loads, most likely is what happens as you are killing zombies in a tower defense game, then you'd get this pause often.

 

I think your best bet is to manually drag the zombie model (just the model) into your scene and drag it under the terrain and make sure it doesn't have mass so it just floats there. That will be your precache loading and now all loading of that prefab, it's the model and textures themselves that take up loading time and pause your game, will be near instant.

 

Note this will be common practice for dynamic things in all your games. You always want to load 1 of said model at the start, most likely just drag it in at design time, and keep it loaded throughout the game so subsequent loads will be instant and not affect your FPS.

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...