uNet rigidbody movement latency issue - unity3d

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.

Related

How to prevent sliding with rigid bodies in Unity?

So, I am using Unity's Rigid body physics engine. And I made the player using a capsule collider. And after creating another rigid body with a Box collider I tried to jump onto it, only, the player starts to ever so slightly slide on top of it until eventually sliding off.
I want to be able to make the player jump onto movable objects without sliding on top unless there is enough of a slope to make sense for the player to slide off of. Is this possible, or does Unity's physics engine prevent this?
This can be achieved by applying a Physic Material to the player's capsule collider. Specifically, take a look at the Dynamic Friction and the Static Friction of the Physic Material. You may also want to set the Friction Combine to Maximum, if you want to ensure your player has a good grip on the platform regardless of what kind they land on.
A higher Dynamic Friction will quickly stop your player object if it starts sliding, while a higher Static Friction will make it harder for the player object to start sliding if it is otherwise stationary.
There isn't an exact science behind choosing these values; you'll really have to play around with it to see what feels right for your game.

Climb down ladder in 2D platformer game

For my game, the player character requires to climb up and down ladders those are placed in the gameplay area.
At present, I can able to climb up for my player character to climb down at present I don't have anyway. Because platform box collider applied with platform effector, so for the climb up, effector does not create any problem but now after reaching the top, it becomes solid platform so now I can't able to move downside.
For climbing up, I have followed this tutorial: How To Make 2D Ladders In Unity - Easy Tutorial
I am looking to implement some physics so I can reach downside to the ladder after reaching top.
You need 2 boolean variables isClimbingUp and isClimbingDown which depend on pressed key and a second ray, which will check -Vector2.up direction. Then just add one more 'else if' statement for down direction.
Yes, I have managed to solve this, and the game is published in the stores.
You can check using the below link:
Humpty Trumpty's Border Wall
This is my overall physics setup for the stair:
I have applied a trigger collider to my stair object and disable player gravity scale when the player within the stair.
Then after within the trigger enter and exist, I have done this:
Physics2D.IgnoreCollision(m_CapsuleCollider, myStair.platformCollider, false);
Disable collision between player and platform colliders when the player is within the stair.
I don't think, Platform Effect 2D becomes useful to me in this process but I didn't remove this to remain in the safer side.
So you have to keep a reference of the platform object which is attached to Stair.
I hope you will get a general idea to solve this problem.

How to synchronize projectiles with Photon in 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

Unity OnTriggerEnter triggering wrong

I have a game in which I want my player to jump from one platform to the other. On my platform I have a box collider.
When I tried to jump, sometimes my player would hit the side of the collider and start grinding up against it and would slip down and finally trigger the death condition. To prevent this, I put a trigger collider next to my platform. I also put the trigger collider slightly below the box collider so that in case my player jumps on the edge, he doesn't activate both.
If the trigger activates, I play the death function, otherwise I assume the player has made a solid jump and go on with the other game logic.
However, I notice that sometimes when the player lands on the edge of the platform it enters the on collision function as well as the on trigger event.
This is strange because I notice in my scene view that the player collider has not entered the trigger collider below the platform.
I have tried adding raycast to the mix but I'm still getting this bug, and even despite the raycasts I don't understand why OnTriggerEnter is triggering when the player hasn't entered the trigger.
I did consider the fact that the player collider might push into the platform collider since the player is falling with some speed but I thought it would show up in the scene view.
My question is, when I land on the platform collider how is it possible for the trigger collider to trigger? I'm jumping on top of it, not from below it. If I miss the platform completely the trigger fires as expected but on occasions it will land on top of the platform have no overlap with the trigger collider and still fire it.
/e
this is a side on view of my 3d environment. It is not the exact depiction but to simplify it for you guys. My player is jumping from one platform to the other, both of these platforms are for all means and purposes 3d cubes with box colliders. In between the two platforms but at a slightly lower level I have a trigger collider.
when my player hits the trigger collider its game over. my question is sometimes my player will land on the edge of the box collider as in the sketch but for some reason it will trigger the gameover trigger collider when there is no penetration of my player collider with the trigger collider, as you can see there is plenty of space in between them they arent even touching.
To sum up - my ontriggerenter is running when there is no visible contact between my player and the trigger collider, question is why?
ignore the draw ray, as you can see, my player collider is firmly on top of the platform box collider, and yet ontriggerenter for the collider next to and below the platform is triggered and my player goes into death animation. I cant be more specific then this, its up to you guys to help me out now and explain why this is happening. my player is far away from the triggercollider they arent touching.
As always, no response from Stackoverflow.
Anyways I was able to find a solution to my problem. The solution was ugly and its not worth sharing but for anyone else stuck with collision detection and such the following things or a combination of the following might help you find a solution.
1 - You can consider changing the rigidbodies colliding between each other to continuous or continuous dynamic. This will increase performance overhead but will lead to much better collision between the rigidbodies.
2 - In settings, physics manager you can try to turn up the Default Solver Iterations. From the documentation: Solvers are small physics engine tasks which determine a number of physics interactions, such as the movements of joints or managing contact between overlapping Rigidbody components. Use Default Solver Iterations to define how many solver processes Unity runs on every physics frame. This affects the quality of the solver output and it’s advisable to change the property in case non-default Time.fixedDeltaTime is used, or the configuration is extra demanding. Typically, it’s used to reduce the jitter resulting from joints or contacts.
These or a combination of these might be something to look at.

How to restrict which colliders are triggered?

Sorry if similar questions have already been asked.
I have a character that can hold up a shield to block incoming damage. The character has a circle collider for his body space. The shield has a box collider that blocks off a portion of whatever direction he's facing, and it's only enabled when the player is holding down a button. My enemies have weapons surrounded by triggered box colliders which are enabled when they decide to attack.
So, my problem is that when my character is attacked while shielding, sometimes his body collider is detected and sometimes his shield collider is detected. I can't find any consistency no matter what I try.
[Screenshots] (http://i.imgur.com/VHujbcG.png)
[Code] https://gist.github.com/siketh/2401454977d10ed7699b
I've been struggling with this all day and need another set of eyes. This isn't a serious project so if you need to see anything else I'm happy to post more code or explain more of my design.
It's probably because the weapon intersects with both the character and the shield at the same time. There are great tools in Unity if you want to see if that's the case.
Notice that Unity has "Play", "Pause" and "Play one step" buttons at top of the editor window. You can pause the game with Debug.Break(); instantly at the moment player fires or swings the weapon. Then you can watch what's happening step by step. Select the character, the shield and the weapon so that you can see their colliders in action. This way you can see what collides with what exactly step by step.
Similarly you can see the action in slow motion by adjusting time scale. Something like Time.timeScale = 0.1f;
To prevent this,
You may want to look at continuous collision though I've always failed to use it properly in Unity.
You may want to utilize more physics layers. http://docs.unity3d.com/Manual/LayerBasedCollision.html
You may want to detect collisions by using raycasts.
You can enlarge the shield and reduce the weapon swing speed or bullet speed. So that it's impossible to penetrate through shield.
You can decrease the period of FixedUpdate calculations so weapon movement will be smoother and there will be less penetrations.
http://docs.unity3d.com/Manual/class-TimeManager.html
There is a high probability that you are detecting both weapon-to-shield and weapon-to-player collision in one step. So why not postpone the decision one FixedUpdate later. So that you can check if there was only weapon-to-player collision or both collisions. If weapon-to-shield collision detected in previous update, then you know player hit the shield no matter if weapon passed through the shield or not.
Let's say there is no way you can detect if weapon hits the shield or the player. By using some simple geometry, you can check if the attack is coming from the direction of the shield or not.
Good luck :)