Hello everyone.
I am currently creating a multiplayer game in which players have to escape from a monster.
So I use the AiMoveTo node to direct the monster to the pawn of the player in question.
Still, the monster can only chase the server player, no matter what I do. My last solution was to use the player ID using the player State node and player ID, but this time the monster doesn’t do anything anymore.
So I’m asking here if anyone would have a solution.
Thank you!
Monster BP :
Yep, totally. the playerID is very big. I tried to use 0 and 1 but the monster detect only the id 0.
I need a solution for detect 0 or 1.
i tried to use variables and get the id with the get controller ID node, but again, the monster detect only the id 0
One problem you may have is that Playerstate->PlayerID is not going to be a numbet that matches playercontroller indexes like 0, 1, 2, 3, -1, etc. it’s going to be a unique id number that in my experience is usually 3 digits long.
But in your bluepri t your using it to reference a playercontroller by index. which means if the player ID is 230, youre trying to get the 231st player (index 0 is the first player), which probably doesnt exist.
playerid is good for finding a specific player controller or pawn over network by seeing if its PlayerID == the playerID of another player’s playerstates playerid and picking that one but that’s not what youre doing.
I dont think you need to send the monster a target over the network if it can pick one on its own on the server.
You could just GetAllActors of class Pawn and loop through until you find one that is not locally controlled, is not the monster, and has a playercontroller belonging to anyone, pick that one and break the loop (typu can shuffle the getallactors returned array first to make it more random).
or in that loop you can compare playerid to the one passed in from a network rpc if the clients are able to tell the monster to attack a certain player.
But yeah correct me if i am wrong but i bet the playerID is giving you numbers way too big to index a playercontroller.
Okay, i tried something like that, the monster can’t detect the id 1. When the client are detected, the monster chase the server with id 0.
Any ideas ?
CharacterBP :
MonsterBP :
Remote playercontrollers all have index or ID -1 (remember player index or ID is not the same as playerstate->playerid, thats a different concept)
zero and positive number IDs are only given to players that belong to the machine that’s accessing them, so player index 0 on the client machine will be player index -1 on the server, and all the players that have gamepads or mouse or keyboard on the server will have their own index 0, 1, 2, etc.
so you really cant rely on the player index to identify a player across the network.
but playerstate->playerid is cool because it is the same value replicated across the network for the playerstate’s playercontoller, so the player controller’s ID will not match the same player across network, but the playerstate’s playerid will.
but really you can skip all that complicated mess by focusing on the pawn instead of the playercontroller.
ok, i see. So, how can i do that ? What is the way for focusing on the pawn ? Use the Get player pawn node ?
Yeah. I haven’t made anything with AI yet so I could be wrong, but it seems to me that the Actor of the Pawn on the Server is considered to be the same Actor on both Server and Client, so it would be much simpler to target that.
The way I would do it is GetAllActors of Class : Pawn, shuffle the returned array, then run it through a ForEachLoopWithBreak, and assign the target pawn for your MoveTo and break when you find a valid one (one that is not the server monster, and that is controlled by a player) You might choose specifically your custom Pawn class that the client players use, to avoid having to loop through any other types of pawns you might have in your game, which would automatically also exclude the Monster pawn). Then you just Break the loop once you found your target victim.
Don’t use a GetAllActors node too frequently as this will really slow down your game. This is a good thing to use whenever the monster needs to “change his mind” but NOT every tick!