Spawning NPCs

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

OhMyOhmit
Posts: 18
Joined: 24 Apr 2018, 12:25

Spawning NPCs

Postby OhMyOhmit » 06 May 2018, 17:15

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

Re: Spawning NPCs

Postby Lapo » 07 May 2018, 07:25

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
Lapo
--
gotoAndPlay()
...addicted to flash games
OhMyOhmit
Posts: 18
Joined: 24 Apr 2018, 12:25

Re: Spawning NPCs

Postby OhMyOhmit » 07 May 2018, 19:50

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

Re: Spawning NPCs

Postby Lapo » 08 May 2018, 06:07

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
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 32 guests