I currently have players spawning in with a click to move functionality moving around a space synced perfectly, but I cant get the bullets to sync properly.
When the player spawns in he creates 60 bullets which are then set inactive and stored until an ability is cast, when the ability gets cast I the bullets get sent active and I have a script that syncs them with all the clients as well, but the bullets are only getting set active on the local client, so the SyncPos script doesn't even run.
Do I need to send a message to a separate game object(ie: the net manager) in order to then send a message out to the other clients and say "hey activate this so you can sync it" or is there a better way? and if so how would I go about doing that.
Syncing a game object's active flag over Unet is not supported, because there's no way to find the game object on the other clients since they're inactive. It's like using GameObject.Find(); it can't find inactive objects.
Related
I'm looking for advice on how to implement online chess move validation using a winboard chess engine. I am creating a mobile battle chess game in Unity 2020.3. Right now I have the possible moves for each player, castle rights, check status, etc being generated by an open source C# chess engine. I chose this engine because it's written in C# and the code could be directly included in my Unity Project. I successfully wrote my own code that connects this chess engine to a 3D battle chess game.
How the game works (video preview):
A piece is selected by the player clicking it with their mouse or
tapping the screen.
The possible moves for the current board are calculated by the chess engine.
I use the possible move indexes to show possible move highlights.
When a player makes one of these possible moves, the move is applied on the chess engine.
It becomes the other player's turn.
I have some custom code to run player animations, based on the kind of move (ex. an attack animation runs when a piece is captured). I also show have screens that show when it's time for a promotion, a player is in check, or the game is over.
I'd like to somehow make the process of calculating possible moves and applying moves to be done on a server. My goal is to protect from players sending illegal moves to the board and breaking the game.
How would you recommend I approach this problem? This is the last thing I need to turn this game into an enjoyable online experience. I just lack the crucial skill of understanding how to make this game online.
On the server, you'll have a separate version of the chess game running.
A player(/client) will send a move to the server (so a unique piece ID, and the target square the player wants to move).
On the server-side, you'll need to check to see if that move is indeed possible. This could be by getting all possible moves from that piece, and checking to see if the intendedChessPosition can be found in the list of possibleChessPositions that was calculated on server-side. Only then, will you actually move the piece server-side.
All players/clients will communicate using the server as the middleman and authority.
The exact implementation could change depending on the API of the chess engine you're using, but that's the basic idea.
Im working on a demo project, where I use Unity 3D and Photon Unity network(PUN) for a real time game.
The person in the top panel is an enemy unit, controlled by another player who does damage to the player on the bottom left (1/3 hp left).
However, the person on the bottom right is a healer who can heal the bottom left player (both controlled by the local player).
Here's my problem! Since it isn't turn based and has to happen real time. How do I design my multiplayer system? Ive previously worked on turn based games, where I just pass the indices and mirror the events taking place locally, in the remote player as well.
But here with latency in the picture, I do not know how to proceed!
What I would like to do is, have the healer heal the player locally as well on the remote player's phone before he is attacked by the remote player or kill the player before the healer can heal his hp depending on the timestamp in which the events happen and reflect such on both the devices.
I think you are confused with some of the pun networking features.
If the healer heals your local player, so will be the remote instances of your local player. Your healing system must be networked of course, make sure you go through our basic tutorial to learn how to implement a simple health system.
https://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/pun-basics-tutorial/player-networking#health_synchronization
What will be slightly more complex than health management is the switch between your player and healer locally. for this you have two main variants.
transfer ownership between the player and healer: https://doc.photonengine.com/en-us/pun/v1/demos-and-tutorials/package-demos/ownership-transfer (this is a v1 demo but the principle still applies to v2)
have a invisible network player, and using your own logic in your game, have the player matching this invisible network player or the healer matching it.
I want to know, is there any way to detect within our game against speed hack applications like game guardian?
I searched all over the internet but I didn't get a satisfying answer.
The solution is not more software on top. The solution is not being vulnerable to this from the start.
Example:
If you allow your users to send your server their coordinates on the world map ("I am the blue player and since I moved my full allowance, I'm now at 156/467"), it's trivial for somebody to write a teleport cheat. Just send different coordinates, boom teleported. Kids play.
If you only allow your users to send messages of intent to your server ("I am the blue player and I intend to move my full allowance in the direction of 156/467") and let your server figure out what that means (is the player allowed to move, what is his allowance, how far will the blue player get in one unit of time) and send the result back, you will never have that problem.
Do not trust client input. First rule of video game security: The client is in the hands of the enemy.
There is little point in shoving more and more software on top of your client if you keep trusting your client. Just stop and design your game so the client can send intent and the server determines outcome.
It depends on your game, but you can try detecting speed hacks by simply checking player position every frame.
Determine maximum possible move distance per second and put it in constant, so that the player wouldn't be able to change that at runtime.
Cache current position.
On next update, check the distance the player travelled and multiply it by the Time.deltaTime.
If the player travelled more than maximum allowed, the player must have cheated.
Return to step no. 2
It will be framerate independent checking as you will be using maximum allowed distance per second.
If the server has all player positions at all time and your problem is with speed hacking the solution is not that hard (assuming player position is being sent to server constantly).
Please do the following, first before updating player position check if the distance between current position and old position isn't too big
var distance = Vector3.Distance(old.position, currentposition);
if(distance<=alloweddistance)
...
and if it is avoid updating position\set player to old position\kick player. A better solution to even that, is to not allow players to send their current position to server, rather send direction they are moving and speed. The server should change their position with the direction and move speed, not client.
I found Solution for my own project that is online multiplayer and it works for any online game.
For solving this problem just we need to calculate time in server. for example we can use stopwatch and doing this in client side... and in an specific situation we can compare them over network and if there was any difference between them, (some thing like more than 3 second) then becomes clear that player is used speed hack.
I tried this method in my game and it works fine.
I'm creating an fps game and I want to have multiplayer. I use the standard character assets from unity but when I join my server with more than two players dey cant see the other player move and when they move both players move. It's like the player move script is run on both players at the same time. So if I press w on own of the clients both players move. I'm coding in c#. no error message but in the console it spams "There are 2 audio listeners in the scene. Please ensure there is always exactly one audio listener in the scene."
standard character assets from unity
player network Identity
Network Manager
You're instantiating a controlled player every time someone joins the server. If they have the same controller components, both of the objects are going to react to controls. Create a non-controllable player prefab and have it react to messages sent from the other clients.
If you have a movement component separate from your controller component, you can reuse the movement component on the non-controllable object.
This is what I have tried.
I have made a 2D body that has child objects connected with joints and I added the photonView component to the body and dragged the child gameObject transforms there. The problem is that it's quite inaccurate and when I set motor speeds it lags and the position isn't the same on the other players screen.
This is probably asked really badly,but all I want to know is how can I correctly synchronize a body with multiple child gameObjects attached with joints.
Also I haven't tried using RPC calls at the moment, but I have a feeling it will make the game lag :/
One problem might be that you effectively setup two different code pieces that both affect the body and it's children: The physics does and now remote players also get updates from the net - with a delay that will corrupt your physical world.
You could disable the physics on the objects which you don't control. Make those kinematic and then update the object only with what you get via the network. It will lag but that's up to you to compensate and hide (and another topic).
You might want to aggregate the updates sent for "your" object with the updates of the children. So you get a snapshot of the whole character/object when it arrives.