I just started a simple enemy AI which adds a sphere trigger to an enemy gameobject for detecting presence of player. It is working fine except that this is only for one single client. How can go about making this multiplayer i.e the enemy can detect and engage multi login player? Will I be able to reuse the same scene for the server component? I am thinking along the line that the client will send in all the player inputs to the server, whereas the server will take charge of moving/broadcasting the player/enemy positions. That said, it means there will be no or little AI/Physics on the client end. Am I on the right path?
Thanks.
You could use a Tag or an attached script to identify the players - then check when AI sphere is triggered if it’s a player. In the case of using a script, perhaps you might have a script “Faction” which has a public factionId - and in this way handle different groups of creatures, etc…
Something like:
…on trigger…
Faction faction = triggerObj.GetComponent( );
if( faction != null faction.IsEnemyFaction( “MyFaction” ) )
{
SetAggro( triggerObj );
}
So each login player would be assigned to “PlayerFaction” perhaps … something along those lines.
Yes, what you are describing is on the right path.
You might think about the majority of it from the perspective of the server rather than the client, so when you write “It is working fine except that this is only for one single client”, you might instead write “It all works fine if this is just the server running everything, but now I need to have clients control the multiple players and have the server send the necessary info back to them”
By whatever means you have your AI discover and track players, that can all happen on the server. The AI positions would be calculated on the server, and then would be updated on the clients via serialized network views, etc.
It is the “secondary” actions and non-critical events that you can calculate on the client sides. This could be things that are not critical that all players see the same way, but also things that are in terms of timing such as explosions or secondary character animations, etc., and those could be triggered across all network connections by using RPCs sent from the server.
Thanks for the inputs. I am new to the server side stuff thus whatever AI stuff I am writing now are just standalone running on my client. As pointed out by priceap, what I am doing now is already probably my server portion except that I have yet to implement the part where I will broadcast the info back to connected clients to achieve a synchronized state across all clients.
try using isServer and isClient, so do an if statement to check if isServer is true - if it is then we enable the script, and if not(else) then the enemy script is disabled. That makes the server to control the enemy script, so that the 3 clients will see 3 enemies one enemy following one player (when theres actualy only 1 of them)