How do I respawn all players of a particular player controller in ue4? - unreal-engine4

Hey guys,
As soon as a certain number of players is reached, a random player is selected and the "CatcherPlayerController" is assigned to him. All other players keep the standard PlayerController.
How do I get all players only with the standard PlayerController and respawn them at different points? The whole thing is for a waiting lobby system in which all players, except the "catcher", have to be respawned as soon as the game starts.
I've tried several approaches but haven't found a solution yet. Thanks in advance!

You could iterate over all players and get the player controller, try to cast it to CatcherPlayerController and if it fails you know it's a standard PlayerController. Since it's a once in bluemoon event I would not be worried about performance issues of all the cast you should do but it really depends on the number of players. Let me know more if I misunderstood your problem.

Related

Instantiating Objects at Different Intervals Unity

I am trying to make a 3D jumping game where my character is standing still and the objects and background are moving towards him to make it seem like he is running. I have a bunch of models for buildings that I am instantiating using an empty game object that I use as a spawner. I want the buildings to spawn one after each other, so whenever one building has moved far enough and left enough space the next one should spawn. I first tried to do this with InvokeRepeating, but the buildings are different widths so it does not work well with a constant repeat rate. I then tried to put a collider on my spawner and spawn a building whenever the spawner collider is not colliding with anything, but it seems to just spawn buildings infinitely. Is there a way to fix this or a better way to do this?
There are many different ways of doing this.
The most straightforward is possibly to let each building spawn the next one, as I assume they each know how wide they are and thus when it's time for the next.
Well , first things first your problem is looking more like a design problem. I would recommend searching things like "procedural world building" , also object pooling. There is lots of examples of runner games that do what you describe.
You can check the palyer position to instantiate , you can create parts of the road as prefabs , make lots and lots of prefabs and instantiate them as you go etc. The question you asked is simply too wide to give an actual answer. So if you have any more spesific questions , it'll be nice to answer !

Trying to get information from multiple gameObjects in a scene

Hope everybody who's reading this is having a great day!
Anyways I'm having a little bit of a problem with a system I want to implement in my Unity Project, basically it's a Enemy ID system. The idea was whenever the player enters in contact with a enemy, it would get it's ID and would use it to instantiate them in a battle scene.
This is the Scriptable Object I'm using as a template for the enemy stats and ID
This is a example of how would the enemy stats look like
And this is the script that check the collisions with the enemies
My problem stand from that I can only get information of one kind of enemy, I've tried making the enemy check the collisions so they would get their own ID, it worked but it would be hell to parse this information through scenes. Is there a way to make the script which check collision detect more than one type of enemy? Help would be very much appreciated!
I would leave a comment, but my reputation isnt quiet high enough yet. Is there a reason you cant use raycasting? I believe you are only evaluating a single gameObject.
Enemy = collision.gameObject;
You then compare that single enemy object
if(Enemy.CompareTag("Enemy")) {
}
You should likely store an array of enemies and check each one on collision enter.

Why player is lagging (local multiplayer)

Why my player lagging? I mean he is moving with 2 fps for enemy. Example: Player1 moves, in his screen all is ok. But player2 see player1 with 2 fps. And the same with player1.
Here is my prefab, and yes, I can't use RigidBody Transform
I think you could find the answer with very little research. The answer is quite simple though.
The reason why it's working perfectly on the client which owns the networking transform is because his input is directly reported to the game. On the other hand, the 2nd player has to send the information about his position to the host or simply the other players. The information is only sent a couple times per seconds.
You could increase the message sending rate of the networking but that's not really a good option. The best option would be to smooth the player's movement by assuming where he is going to be or move the player after it has moved already.
Here is a link about it : https://www.youtube.com/watch?v=Glm0nJ4sO5E

Who should call RPC function while hit by a bullet

My question is simple.
Im creating top down 2D shooter game via PUN2 Free in Unity.
I want to synchronize collisions through network, to avoid lags inaccuracy.
A player is firing a bullet and it hits enemy. I want players to know about all bullets hits(to reduce health, get kill, etc.).
Should I call RPC_Hit() from shooter to other players to inform about actual hit or it would be more wise to call RPC_Hit() from hurt player to other players in game.
Im asking in terms of better synchronization, I guess lags will happen, so in my oppinion it would be better to call RPC function from player which got hit, but then if I would need to send callback only to shooter(for example, to let him now how many dmg he did) it would be hard, cause I can only send RPC to "MasterClient,All,Others".
This bothers me.
I can not find any informations about this.
In same moment the Player1 and Player2 view differs cause of Lag

Using GameCenter for parallel turn based games?

I've played around with making turn-based games using GameCenter. I understand that by default, GameCenter assumes that out of a number of participants, at any given time, one player holds the "play baton", and that this player is the only one who can affect the current game state. Gameplay is asynchronous, i.e. whoever's turn it is can take their time, and the other players will be notified once it's their turn.
So far, so good.
Now I want to use GameCenter to implement a similar, but slightly different kind of turn-based game: an asynchronous game where, instead of a serial player succession, players make their turns in parallel, which are then consolidated into a new game state once all players have "turned in" their moves.
A good model game for this would be Rock, Paper, Scissors: both players secretly decide on their move ("rock", or "paper", or "scissors"). The order in which those are then submitted to the server is arbitrary; i.e. no player should ever get a "not your turn"-type error when they try to submit a move in an ongoing round. Once they both turned in their moves, all player choices are revealed, and the winner of the current round is determined/declared.
The question is: is it possible at all to use the GameCenter infrastructure for this kind of game, either by design or by work-around? And if so, what would be considered a good approach?
It is not possible to implement this with Game Center the way you suggested, but you can take an approach that will look as if you did manage to do this.
When you start a turn-based match, it's always the local player's turn. Either Game Center provides you with a blank match, or you will receive a match in which someone else already took their turn. There is no way to control this, so you need to be prepared for both.
The approach you can take is to have a player always take their turn before you show them anyone else's move. Only then do you check if in your local case, everyone has now taken their turn and you show the result. This will provide the illusion of what you are asking for. In the case of Rock-Paper-Scissors you can now decide the match outcome. The other player will be notified.
However, if not everyone has taken their turn in this round, don't show anything, update the game state as well, but tell the user you're now waiting for others to take their turn. You will be able to show the result when you are notified that it's your turn again, with a game state already indicating the outcome.