How to synchronize projectiles with Photon in Unity3D - unity3d

I have a multiplayer game that synchronizes the movement of the character via photon transform view, applying a Lerp Interpolation for a smooth movement, the shots are synchronized in each client using Photon RPC calls.
I have the following problem, when you move and shoot with a player the other clients observe that the projectiles start in a position in which the player is not yet (this uses Lerp in the synchronization of the movement).
I need to see the projectiles, so I can't make them invisible and only show a shooting animation.
what is the best way to do this?

What you should do is take into account the player position when you start animating the projectile, so that indeed it starts shooting from where the player is and not from where the rpc, which means you also need to adjust the trajectory so that it correct itself to match the projectile real position and direction.
have you tried to minimize the lerp so that it doesn't lag? are you already at the limit of it

Related

How to prevent jitter with Network Transforms in Netcode?

We currently are working on a multiplayer game with Unity Netcode. The game is a racing game with relatively high speed. The player objects get synchronized with the Network Transform component.
We have the problem that the player is lagging a little bit (or junpig some steps forward instead of moving smooth).
The interpolate setting on the Network Transform makes it a little bit better but not completely.
Something we could observe is that when the own camera isn't moving, the other player isn't lagging at all, but since we have a racer game the camera moves all the time.
We could finally fix the problem. More information: https://forum.unity.com/threads/how-to-prevent-jitter-with-network-transforms-in-netcode.1387044/#post-8733624

It is impossible to implement accurate collisions in 3D SpriteRenderers? Is Billboard incompatible with rigidbodies?

I've been having difficulty implementing enemies with a billboarding system for a while:
For a new project I'm reusing some animated sprites from an old static camera shooter game I made. It consisted of shooting projectiles and hitting enemies advancing towards your position. The enemies were capsules which had an animated plane in front of them.
I wanted to go a step further and make a raycast system that would detect if the impact on a plane is on the alpha part of its texture. I achieved it using a SpriteRenderer and a plane that matched the size of the sprite which receives the impact of the Raycast.
The problem comes with the movement of the enemies. If I use Rigidbodies this conflicts with the plane which detects the impact, since I have to use a non-convex Mesh Collider for RaycastHit.textureCoord (With Convex colliders it doesn't return the correct position). I need Rigidbody based movement for the enemies to push each other when colliding.
I tried using Transform Movement, since the error does not occur, but this allows enemies to pass through each other and occupy the same space.
I started investigating navMesh but I'm not sure if it is possible to avoid collisions.
I started to place a group of trigger colliders on the enemy mimicking the shape of the sprite. But this makes it difficult for me to detect collisions when enemies do certain animations (Some enemies jump diagonally or their animations are a bit jittery).
I would like to keep the impact detection system for the sprite, but maybe there is another way to check the texture at the impact location.
I think my options are:
With rigidbody based movement: separate the animation and hit detection system from the enemy movement. And make the billboarding effect teleport to the object constantly.
With Transform movement: Detect if they are overlapping and move them in opposite direction to the overlapping to simulate the collision.
With motion based navMesh: I'm not sure if it will be useful to me, since the characters jump and I also believe that a Mesh Agent ship cannot simultaneously be an obstacle. I understand that the navMesh cannot be generated in runtime.
Leaving texture based detection and using the trigger colliders group: Animate the colliders to also follow the animations. Or simplify everything to a large collider, losing precision on impact.
-Find an alternative method to detect the impact coordinates in the texture, avoiding using RaycastHit.textureCoord and therefore Mesh Collider. (Although I would like to keep the impact detection system as it is, maybe there is a similar approach for the same result).
The reason I have not yet delved into these solutions is because I would like to keep the system simple. I'm trying to avoid separating the enemy into 2 gameobjects, simulating collisions or animating collider positions. I honestly don't know which way to go in order to move forward with the project.

The GameObject passes through the terrain - Unity3D

I am trying to make some kind of simulation program with Unity. The simulation includes a missile launched from an aircraft and a terrain.
I get the coordinate data required for the movement of the missile from another program using a socket connection.
I created an explosion effect for the missile to explode as soon as the missile and the terrain collided. But the explosion effect is not triggered in any way.
I used the OnCollisionEnter() method to detect the collision, but this method does not seem to work.
The missile has its own rigidbody and collider and The terrain has Terrain Collider, but still no collision is detected and the missile passes through the terrain.
What could be the cause of this error?
EDIT :
I thank everyone for their help, but none of the solutions worked. I solved the error using the OnTriggerEnter method. For this, I also had to enlarge the object's collider a little more.
As mentioned in the comment section above (I dont have enough rep to contribute to the discussion but will provide a solution), you need to enable continuous collision detection. Once you have done that we can move onto the next step.
It is generally bad practice to interact with rigidbodies in update and it can lead to all sorts of strange bugs so I wouldn't recommend it. That being said I dont think it's the cause of your issues. As #HumanWrites mentioned, you are manually moving the position each frame which causes your missile to never actually collide with your mesh. the solution to this is:
rb.MovePosition(Vector3.MoveTowards(...))
The reason for this is that by using the method on the rigidbody, you inform the physics engine that you want to move from one position to the other and you would like the physics to take care of this instead of you doing it directly. This allows it to "sweep" between the current position and target position and detect any collisions that would have happened along the way.
Your missile is moving too fast to ever actually touch the mesh within a frame so you need to rely on the physics engine doing that sweep check.

uNet rigidbody movement latency issue

I am making a Multiplayer FPS using this tutorial by Brackeys and am using a rigidbody for Player movement.
If i move forwards on computer 1, then there is about a half second delay until the player stops on computer 2.
I don't know if this is normal or if it stops when you start using paid servers.
Thanks.
Play around with linear drag and drag on your player's rigidbody and see what fits your needs. Usually 999 linear drag and 1-5 drag does the job for me. Also, you should change physics material on your player's collider according to current state - if he is moving set it to zero friction, and when he is not moving - switch to max friction.
For the player you should use a CharacterController instead.
For that very reason.
The traditional Doom-style first person controls are not physically
realistic. The character runs 90 miles per hour, comes to a halt
immediately and turns on a dime. Because it is so unrealistic, use of
Rigidbodies and physics to create this behavior is impractical and
will feel wrong. The solution is the specialized Character Controller.
It is simply a capsule shaped Collider which can be told to move in
some direction from a script. The Controller will then carry out the
movement but be constrained by collisions. It will slide along walls,
walk up stairs (if they are lower than the Step Offset) and walk on
slopes within the Slope Limit.
The Controller does not react to forces on its own and it does not
automatically push Rigidbodies away.

Unity3d Enemy Pushing MainCharacter Back

I am building a simple game where I want to AI enemy to chase and run to my main character and attack it but before I can get to the point where it is attacking I need to figure out this problem.
When my enemy gets to my main character it keeps going forward and keeps pushing my main character back instead of stopping how can I fix this? Both characters have rigidbodies and colliders.
Thanks
The enemy will never be at 0 distance to the player, because the colliders of both player and enemy. It's "impossible" and this means that the enemy will keep on running forward into the player forever.
To fix that, you should set a minimum distance for the enemy AI. This way, the enemy won't move unless the player is out of range.
If you're using Unity's default AI or any other kind of AI from the Asset Store, you will probably find this setting on the script controller. Just look at the inspector and check if you can modify it.
You could try to use "OnCollisionEnter". As far as I know, you could use collider as a trigger of a future action of the enemy and player. Maybe you could set collider in a wider range than that of the characters of yours. Set a specific range that when the player is within that range of the collider it would chase the player and would attack it once it has come to a specific distance then perform the script that you want.