drakth Posted January 20, 2014 Share Posted January 20, 2014 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. Quote Link to comment Share on other sites More sharing options...
DudeAwesome Posted January 20, 2014 Share Posted January 20, 2014 we need the code to tell you what is wrong. 1) may there is a line of code where you set the spawn position? like self.spawn = SetPosition(x,y,z) Quote It doesn´t work... why? mhmmm It works... why? Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 20, 2014 Share Posted January 20, 2014 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. 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 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. Quote Link to comment Share on other sites More sharing options...
drakth Posted January 20, 2014 Author Share Posted January 20, 2014 The script that generates the error is the standard monsterai script. I'll take a look at the Copy() and see if i can figure it out. Thank you both! Quote Link to comment Share on other sites More sharing options...
Rick Posted January 20, 2014 Share Posted January 20, 2014 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. Quote Link to comment Share on other sites More sharing options...
drakth Posted January 20, 2014 Author Share Posted January 20, 2014 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 , 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! Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 21, 2014 Share Posted January 21, 2014 If you call SetPosition(newPosition) on your newly created object, the player wont see a thing since the screen has not been rendered yet. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 21, 2014 Share Posted January 21, 2014 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. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 21, 2014 Share Posted January 21, 2014 Updated with enemy spawning on the first page http://www.leadwerks.com/werkspace/topic/8103-gameplay-tutorial-requests-here/ Quality is a little crappy, but I'm not sure why Quote Link to comment Share on other sites More sharing options...
drakth Posted January 21, 2014 Author Share Posted January 21, 2014 Great tutorial, thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.