I am interested in developing a multiplayer game and was curious to see if A* would possible to use for enemy movement? Would this be bad for performance or is this not possible for online games? I'm familiar with multiplayer game programming, but not an expert :P
I have been using Aron Granberg's pathfinding system for my offline game, and I would be interested to use it in a multiplayer game.
If A* is possible, I would assume that the server would be in charge of that? And if so, so enemy spawning and position tracking (well, at least for this, would the server just send the client the coordinates of the enemy and interpolate the movement?) I haven't been able to find any examples of enemy spawning/movement (maybe I didn't look hard enough? :P)
I have read some of the networking tutorials and M2H's tutorial, but still had to ask this one.
asked Dec 30 '10 at 01:34 PM
I've never used A*, but I have made a game with networked AI using my own pathfinding script.
Basically what I did was, upon network instantiation of the AI enemy, it spawns a copy of the enemy for all connected players (both the clients and the server), with the scripts "EnemyAI" (my pathfinding/targeting/attacking script), EnemyNetworkInit (I'll explain in a second), and NetworkRigidbody, with a networkview observing NetworkRigidbody.
Inside NetworkInit, I check if the player playing this instance of the game is the host or a client ( (If(Network.IsServer) and If(Network.IsClient) ), and if it is a client, i disable the EnemyAI script, and if it is the server, I disable the NetworkRigidbody script (NetworkRigidbody is a script from the networking example on the resources section of http://Unity3d.com, and it syncs and interpolates the local position/rotation of a rigidbody to everyone connected to the game). Since the server is going to be the person actually modifying the position and rotation of the enemy's rigidbody, he doesn't need to interpolate it to himself.
So, in this example, the server has an instance of an enemy with an AI script moving him around by his rigidbody, and the other players' instances of the same enemy aren't running an AI script, but are simply receiving the rigidbody position/rotation changes from the server because they have NetworkRigidbody synced.