Jump to content

Enemy Spawning, Moving objects, and more, questions


drakth
 Share

Recommended Posts

Hi everyone,

 

So, im still doing some prototypes, playing with stuff and testing how everything works.

 

The idea was to have a switch that when triggered it would spawn a monster, so far that parts works well, (and if i manage to fix all the issues im having i'll post it on the tutorials thread), the problems im having are 2 basically.

 

1) When i press the trigger, the monster spawns but it doesnt appear where the object with the spawner script is, it appears somewhere else on the scene, the monster is a crawler i saved as prefab.

 

2) When i spawn a second monster i get an error :( (see attached files)

 

I also notice a delay (probably the models loading) when the monster spawns but this delay makes the whole game freeze while it loads, is there a way to "preload" the models and stuff or some other way to avoid this "delay"?

 

Any help would be appreciated, thanks.

post-9082-0-73757800-1390257967_thumb.jpg

post-9082-0-33812100-1390257984_thumb.jpg

Link to comment
Share on other sites

  1. When you spawn an object it gets placed on the default location Vector3(0,0,0). You have to tell the spawned object to be positioned at a certain location.
     
  2. the first time you load a model, there might be a delay. However the second time you spawn a model, you can use Copy() function. This uses the existing model as a reference. http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/asset/assetcopy-r40
  3. How is your spawning set up? If you are just loading a model then the reason why you have that error is because the loaded model doesn't have script attached. Save your enemy with the script attached as a prefab and load that instead of the model.

Link to comment
Share on other sites

I was planning on making a enemy spawning tutorial tonight actually. Will have something up later in the evening.

 

I also notice a delay (probably the models loading) when the monster spawns but this delay makes the whole game freeze while it loads, is there a way to "preload" the models and stuff or some other way to avoid this "delay"?

 

Drag the model in your scene somewhere where the player can't see it. That acts as a preload.

 

About your error, it sounds like the Start() function isn't getting called since that's where the animation manager is created and the error you are getting is telling you the animation manager variable is null. Are you loading the prefab enemy? If so, just to be save you could call it's Stat() with obj.script:Start(), but Josh has said he fixed this, but there may be an issue still.

Link to comment
Share on other sites

Hi Rick!

 

Yes, it seems the start() function isnt called again, i called the start() function in the Draw() (Probably not a good thing) and it fixed the error.

 

I discovered by pure chance what you just told me about the prefab :D, i just set it to hidden, one question tho, if i set it to hidden i suppose it cant be pushed?

 

Now the doubt i have is, i dont want the object appearing at <0,0,0> when i load it, but then im not sure how to fix that, cause if i move it after its created, the player might see as its created and moved.

 

Any help would be appreciated, and im looking forward to your tutorial! :D

Link to comment
Share on other sites

You don't want to call the Start() in Draw() because Draw() gets called every frame (or so) and you only want Start() to be called once the object is created.

 

Not sure what you mean by hiding it and can't be pushed.

 

If you create and move in the same frame they won't see it moving. It'll just appear instantly. Where you want to place the enemy is up to you. There are a number of ways you can do it.

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...