Unity 3d: Prevent Rigidbody from Falling Over - unity3d

I have a 3d object (army man) that I added a RigidBody to. I have a Gun set up that shoots bullets at the army man --- when a bullet hits it, I want it to fall over. Now I have an issue where as soon as my game starts, my 3d object slowly falls over without any user interaction. I set X and Z freeze positions on the RigidBody but it still falls over. IF I set to freeze on Y position, my 3dObject will not fall over but then if I shoot the army man, it will just spin and not fall over. I attached a screenshot to show all my settings.

Your Collider's mesh is obviously standing on a point and is very unstable looking. Either give him a BoxCollider, or make a tall rectangle, attach a Collider to it and a RigidBody, and make the army man mesh a child of it. Remove all colliders and RigidBodies from the army man mesh.

In the rigid body you also have the option to freeze rotation around a certain axis:

Related

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.

How to deal with nested rigidbody?

I can't seem to wrap my head around the following, I have a simple spaceship with 2 turrets:
My 'Player' the white ship has a rigidbody. The turrets have not.
I'm moving and rotating my player via the rigidBody, however I would like to also rotate the turrets via the physics system.
I thought about adding a rigidBody2D to the turrets, however that was not recommended from my understanding reading posts online. This is because rigidbodies in children would affect the parent in unforseen ways.
So dropping that idea, How can I move my turret and having it be affected by physics?
Some sidenotes:
I want the turrets to be influenced by physics. Lets say i try to rotate my turret, but it hits a wall, I want it to resist. Lets say some debris hit my turret's barrel, I want it to move in the opposite direction.
Although i could move the turret outside of its parent's container (the ship) I do ofcourse want it to 'stay on the ship in game'. The turret is part of the ship, its mounted to the hull or fuselage if you will. So it should move with the ship and keep its position.
As mentioned by derHugo joints where up for the task, although i had to restructure a bit, here is the outcome:
I added an empty transform to hold the ship and its sub-components, so turrets are no longer part of the ship parent, so that i can add a rigidBody to these child objects now.
Then I added a hingejoint and rigidbody to the player ét voila, it now works:
I still need to take a good look at how joints work exactly but this seems to work.

Preventing collider from glitching through terrain

I'm using a terrain in Unity 2019.2.1f1 and a custom mesh of a cave with a mesh collider.
My character that has a Capsule Collider way bigger than the entry of the cave should not be able to enter in. But due to the roundness of both colliders, he can come into force in the cave, glitching through the terrain collider.
I think it's velocity is not excessive, I'm moving the character with rb.MovePosition() in the FixedUpdate(), and I set its rigidbody collision detection to Continuous speculative (tried all the "continuous" modes)
In the animation below, you can see the mesh of the cave and the capsule collider around the character.
How can I prevent this from happening? How can I say to Unity: "I want the colliders to be rock solid and not marshmallow"?
Colliders in Unity are rock-solid. They are incapable of any kind of soft physics, and the only moment they will warp through each other is when you force them to.
Here, you are setting the rigidBody position by force, into an impossible location. The game tries its best to fit your rigidBody despite the lack of room.
You can
Only use forces, and velocities. You can simply set the velocity to the direction of your choosing, and set it to 0 when you stop moving, or use AddForce, which is basically the same thing.
Keep using MovePosition, but use a SphereCast or CapsuleCast to check if you have enough room to move first.

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.

How to move an object without going through colliders

I'm using Unity and i am doing a pong game. I would like to be able to move the paddles with the mouse key. I have tried just moving their position but that of course will simply "teleport" them through the colliders along the edge of the playing field. I tried using addForce() and making the rigidbody fixed in the x position, however, what happens is when the ball hits the paddle, it pushes it and the paddle snaps back. All of the ball's energy is lost (there is gravity in my game). How can i move this box collider but not let it over lap other box colliders while moving? Thanks!!!
Your paddle should be a kinematic (IsKinematic parameter) rigidbody (attached RigidBody2D) collider while the edges should just be a static collider. But, you should control the limits/edges of paddle movement within your script.
If you do things this way, your ball will naturally bounce of the edges and off your paddle. If, however, you want the ball to pass through the edges but notify you of doing so (e.g. lose condition), you should make the edges a static trigger collider (IsTrigger parameter).
Here's a detailed list with all interactions between different types of colliders: http://docs.unity3d.com/Manual/CollidersOverview.html. The messages generated are passed via 2 different functions: OnTriggerEnter2D and OnCollisionEnter2D.