Page 1 of 1

Spawning NPCs

Posted: 06 May 2018, 17:15
by OhMyOhmit
Hello everyone.
I'm trying to spawn NPCs on a standalone Unity client so every player in it's AOI will see them. I want to add some AI to my npcs so they will follow players when attacking them using pathfinding (Unity navmesh), sending their coordinates to server.
I ain't done so much for now - this client is just connecting to existing room.
I've already read this article https://smartfoxserver.com/blog/ways-of ... -game-p-2/ but I'm not sure if it is something I need, because code is on Java, but I need to use it in Unity, so I will have physics, colliders, navmesh, etc.
Questions are:
1. Is this even possible?
2. How to spawn NPCs from client using prepared prefabs so it appears on a server?
3. Is NPC like a standard User or is it MMOItem?
I'm very sorry for noob questions, I'm just learning little by little.

Re: Spawning NPCs

Posted: 07 May 2018, 07:25
by Lapo
Hi
those are actually interesting questions, not "noob" at all :)

Probably the best approach to do this is via the "server-side Unity trick". The idea is to run an instance of your game as an headless unity client on the server side.

In other words you create an .exe of your game and launch it via SmartFoxServer when a Room is created. Then players will connect to the server-side Unity and interact with the Unity server.
This allows you to take full advantage of nav-meshes, physics, colliders etc... and also write your game-specific logic in C#

SmartFoxServer is used to handle logins, database, match making, managing rooms, chats, buddy lists, security etc... and also for orchestrating the launch of these server-side Unity instances.

Depending how your game works you could launch a single server-side Unity where all players will be joined (good for open world type games) or you might need to run a server-side Unity for each game Room you create.

Makes any sense?

If it doesn't we're preparing a series of articles on this topic. The first will be out soon, probably in a week and we plan to provide different examples of how to work with this kind of "hybrid mode".

Hope it helps

Re: Spawning NPCs

Posted: 07 May 2018, 19:50
by OhMyOhmit
Thank you for the answer, it looks more clear now for me. I'll be waiting for this article to come over, this is very great news.

Re: Spawning NPCs

Posted: 08 May 2018, 06:07
by Lapo
Sure, no problem.
If you want to be updated when the article is out subscribe to our newsletter from the homepage.
https://www.smartfoxserver.com/

Or follow us via the usual facebook/twitter and such (links in homepage too)

Cheers