Page 1 of 1

Monster Spawning

Posted: 07 Nov 2017, 03:40
by m0rr0ws0n
Hello :D

I was wondering how you handle monster spawning? I have an idea where the server sends the client the monster type and position and the client spawns the monster. But how do I make the monsters move? Also, I want certain monsters to only spawn in certain areas. Is this possible?

Re: Monster Spawning

Posted: 07 Nov 2017, 08:02
by Lapo
Hi,
sure it is possible and there are different ways.

If you want to simulate the whole thing on the server side you should have the map data in your Extension, so that the server can calculate where to move the monster and know which areas of the map are walkable and which aren't.

Then you can have a timer/scheduler that every X milliseconds (e.g. 100-500) updates the monsters' position. Depending on the type of game you're working on, you don't necessarily need to create the whole animation on the server side. For example if the game is tile based you can send the client the destination tile for the monster and it will make a smooth animation from on tile to the other.

If the game is physics based then you will likely need to continuously update the movement vector and let the client smooth the animation out. An example of this is our Space War game, which you find in our Example packages.
http://docs2x.smartfoxserver.com/ExamplesUnity/spacewar

Hope it helps

Re: Monster Spawning

Posted: 09 Nov 2017, 00:18
by m0rr0ws0n
Ok thanks. Do you have any idea how I can get the map data from Unity? I'm using the basic terrain and its sculpting tools from Unity. Sorry I'm new to this sort of thing. 8)

Re: Monster Spawning

Posted: 09 Nov 2017, 10:07
by Lapo
Good question. There's no straight answer, it depends on the type of game, the type of game maps etc...
In some cases you can use a mix of client and server logic to avoid too many complications, such as having a copy of the game map on the server side. Other times you may indeed need that.

For example you may just need several "spawn point" coordinates so that the server can generate the enemies, then the client will implement the movement and collision detection logic.

The next step could be to have some sort of data file (JSON, XML or similar) that provides the server with data about the map, such as a walkable areas, trigger areas etc... This way the server logic can handle paths, collisions etc...

Makes sense?