Hey everyone,
I am working on a multiplayer game which every player controls a vehicle. All the vehicles are copies of the model which has the tag “Player”.
I am doing a AOE effect for a weapon that requires me to go through the list of all the players based on position, eliminating those who are not in range and doing calculations for those who are then send an RPC to the clients to deal damage.
I’m having problem accessing the positions of the players and identifying enemies and myself in game.
The damage calculations all work fine when testing alone however, I don’t know how to run though all the other players and identify them to deal the damage. Like how do I lets say there is 5 players on the map and players number 3 in the list is in range, how do I single him out to ask his side to do damage calculations?
Also I’m using photon cloud and don’t quite understand how or using what method to achieve this effect. I know that I want to
- Go through list of all players in map.
- Only concentrate on those in range
- Send a RPC call to respective players to ask them to calculate damage
- Deal damage
void DamageCalculator()
{
//Set maximum damage
damage = 30;
//Get list of players
GameObject[] Players;
//run through amount of players and listing them out
for (int i = 1; i <= GameObject.FindGameObjectsWithTag("Player").Length; i++)
{
Players = GameObject.FindGameObjectsWithTag("Player");
print("Players: " + Players);
}
//Get distance between mortar position and player position
float DistanceDiff = Vector3.Magnitude(transform.position) - Vector3.Magnitude(Players.transform.position); print("Bullet Pos: " + Vector3.Magnitude(transform.position));
print("Player Pos: " + Vector3.Magnitude(Players.transform.position));
print("Difference: " + DistanceDiff);
float DamageMulti = (1.0f - (DistanceDiff / 100)); //Get the damage multiplayer number based on distance
if (DamageMulti > 1.0 || DamageMulti <= 0.0) //If out of range
{
damage = 0;
print("Damage Dealt: Out of Range");
}
else if (DamageMulti <= 1.0) //If in range
{
float temp = (DamageMulti * damage);
damage = Mathf.RoundToInt(temp);
print("Damage Dealt: " + damage);
}
}