NPC as MMOItem detecting User

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

NPC as MMOItem detecting User

Postby OhMyOhmit » 09 Jul 2018, 18:16

Hello everyone.
As you recommended me before, I use Unity Standalone Client for managing npcs in my room. So far I've done so when specific client connects to the server, MMOItems spawn on a location I need. Not so much, I know.
Now I want it so when npc(my MMOItem) detects a player nearby, it starts to follow him using Unity's navmesh. I've found some tutorials of how to do such things, but I need to get player's transform for a script(which is in USC) so npc will start to follow him. I don't have "player's object" in my "Unity Hierarchy", maybe because of AOI. I don't have my npc there neither. But I can see my npc in my main Unity window(which will be used by players).
Shortly, I don't know how to get players near my MMOItems(npcs) in Unity, because I can't see them.
I hope you will understand my problem, I know how bad my explanation is :lol: If not, I will attach some screenshots later.
OhMyOhmit
Posts: 18
Joined: 24 Apr 2018, 12:25

Re: NPC as MMOItem detecting User

Postby OhMyOhmit » 10 Jul 2018, 15:16

Another idea came to my mind but I'm not sure if it is better ther previous one. At least, I have an imagine how to realize this one. So, I was thinking about checking players' coordinates with USER_VARIABLES_UPDATE and if they collide with NPCs' "aggro-zone", then I'll send a request to client with the information I need. The only problem I see is that I have to check every players' and every NPCs' coordinates in a room. Will I have a problem if I have like 100 npcs and ~50 players in one room and I'll have about 10 rooms like this?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NPC as MMOItem detecting User

Postby Lapo » 11 Jul 2018, 08:12

Hi,
I am sorry, I am not following entirely.
It sounds like the problem is more of a Unity coding issue where you need to be able to reference the player's object in order to follow it.

You said you don't have the player's object in the Unity hierarchy. Yes, of course you don't, because players are spawned at runtime when they connect, but the spawning is done by your code, isn't it?
So all you need is to keep a reference to each player's object currently in the game and pass them around to the "navmesh follow" function/class when you need it.

Make sense?
Lapo
--
gotoAndPlay()
...addicted to flash games
OhMyOhmit
Posts: 18
Joined: 24 Apr 2018, 12:25

Re: NPC as MMOItem detecting User

Postby OhMyOhmit » 11 Jul 2018, 16:16

Lapo wrote:Hi,
I am sorry, I am not following entirely.
It sounds like the problem is more of a Unity coding issue where you need to be able to reference the player's object in order to follow it.

You said you don't have the player's object in the Unity hierarchy. Yes, of course you don't, because players are spawned at runtime when they connect, but the spawning is done by your code, isn't it?
So all you need is to keep a reference to each player's object currently in the game and pass them around to the "navmesh follow" function/class when you need it.

Make sense?

It does. But the problem is that I DO see players and mobs(MMOItems) in my main client, which is for playing, and I DO NOT see them in my NPC-Client, which I use to control npcs on server-side, because of AOI - I do not even spawn a user by NPC-Client, it just connects to server, so all I see is my map(but this is not the main problem). That's why I thought that maybe the second idea is a better solution: check players' and mobs' coordinates by smartfox and if one of the players is in aggro-zone of some mob, then I just send this player's coordinates to a mob everytime player is moving (his x,y,z variables are changing) and in Unity I just move my mob with navmesh. What do you think? Would it be laggy?

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 41 guests