Monster Spawning

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

m0rr0ws0n
Posts: 11
Joined: 22 Sep 2017, 12:11

Monster Spawning

Postby m0rr0ws0n » 07 Nov 2017, 03:40

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?
User avatar
Lapo
Site Admin
Posts: 19645
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Monster Spawning

Postby Lapo » 07 Nov 2017, 08:02

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
Lapo
--
gotoAndPlay()
...addicted to flash games
m0rr0ws0n
Posts: 11
Joined: 22 Sep 2017, 12:11

Re: Monster Spawning

Postby m0rr0ws0n » 09 Nov 2017, 00:18

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)
User avatar
Lapo
Site Admin
Posts: 19645
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Monster Spawning

Postby Lapo » 09 Nov 2017, 10:07

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?
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 6 guests