Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 1 more developer from Canada and 12 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


Mob/NPC's AI in a MMO with Unity + Custom Server


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 bernatripoll   Members   -  Reputation: 122

Like
0Likes
Like

Posted 07 May 2014 - 08:22 PM

've created a basic MMO system using Unity3d and a custom c# server. Right now, players can walk and attack eachother and it works great!

Now, I'm implementing the mobs system and I'm not sure how to do it, here's my thoughts!

Spawning

  • The server spawns the mobs on the world based on a % (This works great)

  • Then, players can see the mob fixed on the position where the server spawned it.

Moving mobs

  • I'm not sure how to do this, I've thought about 2 options

    A) The server changes the position of each mob every X seconds (say 3-4) and sends the new position to all the players around, then each player starts moving the mob towards that position. I know this would cause that different players sometimes see the mob on different locations...

    B) Every 3 or 4 seconds (same) the server sets a new final position for the mob, and every 0.5s (server sends sync snapshots every 0.5s), sends the mob position to all players around. This seems a better solution but there's gonna be so many packets travelling around...

Mobs Attack Players

  • Using the option B) for moving mobs around, the server could detect when one player P is close enough to the mob M, so M should start attacking P.

  • But here's the big question the server doesn't know ANYTHING about the terrain so, now M have to go towards P to 'kill him', but the server can't do the pathfinding algorithm to move M to P's position... So I came with an idea!

Idea!

  • When the server sets M to attack P, then P gets the control of M so the player starts controlling the mob and makes it go towards him using the pathfinding algorithms of unity! Then, the player every 0.5s is going to send his position and M's position to the server, and the server updates M's position exactly where P said it has to be.

  • When the server detects that M is close enough to P to attack, M causes damage to P even if he's still running away and M is going after him.

What do you think? Would it work? Any better solution? Thanks :)



Sponsor:

#2 Valoo   Members   -  Reputation: 574

Like
0Likes
Like

Posted 07 May 2014 - 11:20 PM

I'm currently doing a similar thing (online rpg kind of game) and i came to the conclusion that, atleast for me, it seems inevitable to have the server not be a Unity instance too, if i want to handle physics server sided. I'm also using Aron Granbergs A* for pathing and skills/spells (teleporting for example, like guild wars 2). I read somewhere that he planned the possibility of it to be run outside unity (Photon i believe), but haven't seen any further mention of that.

But for now it works very well inside unity. i send position related data (position, velocity, y-rotation) 5 times a second and the difference on the client is very acceptable (interpolated and halfway extrapolated).

 

Also, dont let the player control any mob. I have once seen a game doing that where you could pull all mobs in the area towards you using a hack and one-hit kill them.

If unsure maybe just do the movement (mob to player) in a straight line (some Wow private servers do that, if pathing is not enabled). The Mob will most likely run through walls and all that but thats better than giving the player an opportunity to cheat for free.


Edited by Valoo, 07 May 2014 - 11:26 PM.


#3 hplus0603   Moderators   -  Reputation: 7867

Like
1Likes
Like

Posted 08 May 2014 - 10:39 AM

the server doesn't know ANYTHING about the terrain


You likely need to fix this.

There are a few ways to do this. For example:
- You could run the same physics on client and server
- You could pre-process the game level to generate a simplified "walkable mesh" for where the monster can be/see and run a different physics simulation on the server
- You could give each monster a "must not leave area" defined by a rectangle or polygon, and it just stays in that area, and have artists define this area for each monster, and make sure there are no walls in that area
enum Bool { True, False, FileNotFound };

#4 ferrous   Members   -  Reputation: 3367

Like
0Likes
Like

Posted 09 May 2014 - 03:34 PM

 

 

Idea!

  • When the server sets M to attack P, then P gets the control of M so the player starts controlling the mob and makes it go towards him using the pathfinding algorithms of unity! Then, the player every 0.5s is going to send his position and M's position to the server, and the server updates M's position exactly where P said it has to be.

  • When the server detects that M is close enough to P to attack, M causes damage to P even if he's still running away and M is going after him.

What do you think? Would it work? Any better solution? Thanks smile.png

 

 

The danger there is that you just handed M off to P, and the client is untrustworthy, and could be telling the mob to do whatever it wants the mob to do -- like go towards other players, or stand still while getting attacked at range.   I think in the long run, you're really going to want the server to have some idea of the terrain.  It doesn't need everything, and should probably get by with just the underlying navmesh.  (or grid, or whatever you're navigational representation is)






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS