When i add rigidbody, animation makes player float. In Unity - unity3d

I am trying to play the animation but whenever i add rigidbody, player starts to float in the air at the constant value (which is 3.5 Y). No script is attachted atm.
I tried to remove rigidbody which solved the problem, but i need it so deleting rb is not an option. Gravity values are normal and the other animations are from mixamo (i didn't do the animations).

Based on the information provided here is what I'm thinking:
The root cause of this is that your character model when effected by gravity is being pushed to the ground and foot IK is causing the legs to end up looking like your screenshot above.
Some common approaches to this problem:
Create an empty object called player (Controls Rigidbody/Capsule Collider/Character Logic)
Add the 3d Model as a child of this object (Animator/Mesh/etc).
On the root object add your rigidbody as well as a capsule collider (prevents character model from colliding with the environment due to gravity).
With this setup animations can be done on the model (+foot IK) without gravity causing issues.

Okay i just solved the problem. Problem was neither rigidbody nor animation.
The collider of mesh (ground) has option checked "is Convex". I turned it off, problem solved, player is not floating anymore.

Related

issue with character controller collider in a c# unity 3d game

I'm having a peculiar issue with my character controller collider. in the image provided the controller SHOULD fall down the side of this cube object, yet it "floats" or "hangs" on the corner which isn't a detrimental problem, but is something I'd like to fix now rather than later, any ideas?
image of the controller statically floating on the edge of a cube object
I initially thought this issue may of been caused by incorrect properties within the controller, however after experimenting with the values the issue has not be resolved. I even tried ray casting to determine whether the controller is actively colliding with an object, but to no avail.
The problem is
it seems that the problem isn't directly on the collider but rather on the material you're using (which in this case, none)
Solution
from your project's asset, right-click and select create -> Physic material. From that physic Material, set the both Dynamic and Static friction to zero, then just draw that physic material to the game object. you can also adjust the friction depends on your needs
Character Controller has a skin width. Its an extra layer of collider which may cause this. Also check if the collider is within the capsule bounds. You can check out this article on Unity Character Controller for more details.

Strange behavior with collisions in unity

I have a gameobject player that has a character controller and a gameobject cube that has a rigidbody.
I'd like to make my character go through the cubes like a Trigger. Except that I want the cubes to keep their gravity and physics.
I did a little research and found Physics.IgnoreCollision or the layer collision matrix. Both methods work, I get through my cubes well, except that I have a weird behavior that makes me feel like I'm bumping into each one of them, so I find myself slowed down in my momentum...
Is there a solution to my problem?
In the Unity menu bar, go to Edit > Project Settings, then select the Physics category to open the Physics window. You will find a Matrix and here you can uncheck the collision between 2 layers. If you put the cubes in a layer and the player in another layer and in the matrix you uncheck the box, cubes will maintain their properties and player will pass through them.

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.

Child Components with rigidbody

Context
I have in my project two elements. A player (just a cube) and some eyewears.
When the glasses aren't attached to the player, i want them to have properties of a Rigidbody. But when the eyewears are attached to the player, i want them to be a static object, so the player can process the collisions and physics.
I have tried:
DestroyElement(rigidbody) when the player pickup the eyewears. When he leaves them, i recreate the rigidbody with AddComponent
It worked nice, but in the future other elements will be attached and they will not share the same properties of rigidbody. I though maybe i could save the rigidbody instance, so when the player leaves the glasses i assign it to them. I could't.
AddComponent don't accept arguments.
Then i tried to set "kinematic mode" when my player wears the eyewears. It didn't go well, my player can't jump anymore and sometimes he glitches in the floor.
How can i resolve this?
GameObject.AddComponent does take an argument, or a generic argument (preferred):
go.AddComponent<RigidBody>();
this is also possible, but deprecated, since you lose type-safety:
go.AddComponent(typeof(RigidBody));
However, RigidBody is not meant to be added/removed, and in your case I would say that kinematic mode is the way to go... but I can't tell why you're experiencing weird results with it.
Thanks to R Astra i checked again the eyewear collisions and i found out the problem. I had enabled the Convex mesh.
The col was causing trouble because the back meshes were inside the player
So, quickly i copied that eyewear and generate a new mesh. It worked!
Thank you very much!

Object moves on own with rigidbody

I have an object in unity with a rigidbody attached to it. For some reason, the object moves forward on the Z axis, even though no script is telling it to.
Does anyone know why this is happened?
(some notes, isKinematic is turned off, freeze x, y position are on, free x, y, z position are on)
An Object does not need to have a script directly attached to it for it to move. A script that is attached to another GameObject can also find this GameObject and be able to move it.
You should disable all other GameObjects with scripts. If they contain any script that is moving this GameObject, you will find out.
Another big possibly I've seen several times is the Animation or Animator component. These two components can move a GameObject and I suggest you remove any of them that is attached to your GameObject. It is very likely this is the problem.
An impulse could have affected it, and the velocity is still up.
Do you have windzones in your scene?
Try to disable the ridgidbody during play, if any script is acting on your Ridgidbody, you will get an error pointing to the class trying to use it.
Disable the collider, see if it still moves.
If colliders are too small, ridgidbodies tend to "dance"
SOLUTION: In inspector freeze rotation X and Z in the Сonstraint of Rigidbody.
Perhaps this is a bug of the physical system. In my case, the capsule began to spontaneously go up the slope, even without any scripts and animation. Unity version 2021