x


A* Pathfinding + Multiplayer/Online?

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.

more ▼

asked Dec 30 '10 at 01:34 PM

SirVictory gravatar image

SirVictory
1.7k 66 77 104

If you are going for a client/server approach for handling multiplayer. Then yes, you could make the server responsable for using pathfinding and movement of your player units. Then the client would be responsable for sending input to the server, e.g. I press the forward-button, this action is send to the server, which actually applies the forward movement to my avatar. The server then sends the new position and rotation back to my client. And again yes, you can use interpolation to make this movement look more smooth.

Dec 30 '10 at 06:44 PM Ejlersen
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Dec 30 '10 at 07:58 PM

PrimeDerektive gravatar image

PrimeDerektive
3.1k 57 64 84

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1370
x682
x654
x252
x113

asked: Dec 30 '10 at 01:34 PM

Seen: 1952 times

Last Updated: Dec 30 '10 at 01:34 PM