#Capture the flag
1 messages · Page 1 of 1 (latest)
For this case you would probably have a game manager keep track of things rather than the flag or the player. That way you make a global notice that the flag has been taken or dropped. The trigger can fire an event that the manager is listening for. Triggers fire for both clients and server so you don't really need to send any messages over the network.
hm I see. so the game manager would keep track of the flags' booleans?
That's the way I would do it. You do have to take care that the game manager class doesn't get too bloated. You might want to split it off into its own ctf manager
I did just that, yeah
that being said I am quite dense when it comes to events and triggering them
should I just do CTFManager.Instance.Whatever() when inside OnTriggerEnter?
and then, in CTFManager, I do everything player-related?
I don't use singletons. The flag itself would have a static event like FlagTaken<Player>. Then on trigger would called FlagTaken.Invoke("Player that took the flag"). Ctf manager would be listening for all flag taken events then update UI and what not accordingly
I rearranged things, but the problem remains visually
everything is being detected just fine, but the client isn't seeing the flag on their backs as they should. one second
if blue touches his base flag the points get calculated as expected
in the CTFManager I'm doing
player.hasFlag.Value = false;
player.FlagUpdate();
which calls the player stats
public void FlagUpdate()
{
if(flagCarryObject != null) flagCarryObject.SetActive(hasFlag.Value);
if(flagCarryEffects != null) flagCarryEffects.SetActive(hasFlag.Value);
}
hasFlag is a network variable
public NetworkVariable<bool> hasFlag = new NetworkVariable<bool>();
with default permissions
hm actually scratch that, the points only update for the server as well
so it's the same problem in two places, basically
I would use hasFlag.OnValueChange event to toggle the flag on the players
Are the points in a network variable?
will that help with only the server being able to track changes?
they are in the regular game manager, yeah
NetworkVariable<int> T1Points = new NetworkVariable<int>
(5, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
NetworkVariable<int> T2Points = new NetworkVariable<int>
(0, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
don't mind that 5, it's for testing purposes
Is it just the UI that isn't updating? Or are the network variables not syncing?
the UI changes just fine...server-side
seems like a sync issue
you can see the right window, the host, updates blue's points just fine
are you sure I'm not just missing a sync command of sorts that should be called when I want to update things network-wide?
still no dice
public bool hasFlag
{
get => _hasFlag.Value;
set
{
if (_hasFlag.Value != value)
{
FlagUpdate();
}
_hasFlag.Value = value;
}
}
public void FlagUpdate()
{
if(flagCarryObject != null) flagCarryObject.SetActive(!_hasFlag.Value);
if(flagCarryEffects != null) flagCarryEffects.SetActive(!_hasFlag.Value);
}
could this be related?
Network Variables get updated automatically so no other commands are needed.
That is usually when you are updating a network variable in start or awake before the object has been spawned
it's getting called because of this line
if (joinTeam) { JoinPlayerTeam(tnum).Value += 1; }
which is triggered by the player spawning via OnNetworkSpawn
unfortunately commenting the code doesn't really fix anything so I guess that's not where the issue lies
here's the full OnTriggerEnter after changing things to CTFManager
void OnTriggerEnter(Collider other)
{
PlayerStats player = other.GetComponent<PlayerStats>();
if (player == null) return;
if (IsServer)
{
if (!string.Equals(player.tag, tag) && !CTFManager.instance.IsFlagTaken(team.teamID) )
{
CTFManager.instance.TakeFlag(player);
}
else if(string.Equals(player.tag, tag) && CTFManager.instance.flagCarriers[team.teamID] == player)
{
CTFManager.instance.ReturnFlagFromPlayer(player);
GameManager.instance.AddTeamPoints(team, 1);
}
}
}
I'm still using singletons for now since they aren't the source of my problem
I think the problem stems from if (IsServer), but without that the game complains that the player doesn't have access to the variables trying to be changed
or at least something like that
any ideas? I'm drawing a complete blank
the project's pretty small if you want to take a look at it
Yea your network variables are server write only. I think probably is the Singleton. When the player connects it spawns any in scene network objects. This can cause duplicate Singletons and cause it to destroy the original and then you lose connection to the network variables
anything short of constantly updating the characters' meshes on FixedUpdate is coming up short
so do I just Invoke basically everything that would use a ----Manager instead?
That or you can grab a reference of the Manager with FindObjectByType
nope
made the manager a regular game object, found by type on awake, tested
same error
so it's not a singleton issue
Its not a Network Object?
make sure the game manger is still getting the reference to the score roller masks. usually when they spawn in it can lose those scene references.
doesn't seem to be the case
is that on the host or the client?
client. also tested on the host