Unwanted bounce on edge - unity3d

There are two planes next to each other. Each plane has a mesh collider. Randomly, when the capsule (with a rigidbody and a capsule collider) crosses the edges it bounces.
Do you know why ?

This normally happens if the planes don't align. Make sure there is no gap between the planes and that they are on the same y position.
If this won't fix you problem, you might want to consider using Unity's CharacterController and adjusting the step size which will, rather than bounce, slide/snap the player to position.

Related

Unity player boxcollider 2d Contacts Normal Vector bug

This bug occurs very rarely (probably 1 in 100 collisions with a platform) where the players box collider 2d have contacts with the platform horizontally (two contacts with (-1,0) vectors and two (intented) with(0,1)). This is very problematic because the player cannot jump forward (just jumps up without any x velocity) and it looks like it hits an invisible wall. I tried increasing the default contact offset in the physics 2D settings to 0.01 but it did not help. I am creating a pixel art game with 16 Pixels per unit.
After researching I finally found a fix for my problem. My problem was that the player got stuck inbetween my tiles each having a boxcollider with the TilemapCollider2D. I fixed it by removing each collider to one whole with a composite:
add TilemapCollider2D to the tile layer's component
check "used by composite" field in TilemapCollider2D
set Rigidbody2D to static
I had to check composite collider to polygons because otherwise I could not apply any Force to the rigidbody somehow.

Unity3D Collider Passing Through Other Colliders

The Problem: Mesh colliders on some rigidbody objects are passing through colliders on other objects.
Things I have tried:
With the assumption A is a GameObject with a RigidBody attached and B is a normal GameObject with a collider.
Give A a convex mesh collider
Give A a non-convex mesh collider
Give B a convex mesh collider
Give B a non-convex mesh collider
give B a box collider
give B a convex mesh and box collider
give B a non-convex mesh and box collider
Adjusting the weight of the rigidbody
I have tried all of these in all combinations of A and B.
In addition,
Colliders are not marked as triggers
All objects are on the default layer (0)
Checking isKinematic; doing this seemed to make gravity stop affecting the object, so I have left it as false.
Constraints: I want A to use a mesh collider since most of the objects involved are moderately complex, and fitting other colliders to them would take a while.
Weird Behaviour: I have some objects with both rigidbody and convex mesh collider where the collision is working fine with a non-convex mesh collider. This is inconsistent with other gameobjects. The objects have all of the same settings.
I am using unity version 2019.3.11f1 if that is relevant.
The object being used are from this package. Specifically, the filing cabinet with rigidbodies on the drawers works fine. The desk, office chair, pen, and open laptop all fall through the "floor" (a cube with all of the above colliders tested on it).
Do you have 'isKinematic' checked on the objects with rigidbodies that are going through other colliders? If so uncheck it so that external forces affect it.
edit you also need to click convex on the mesh colliders if they are colliding with other mesh colliders, Convex Mesh Colliders are limited to 255 triangles, are the objects that are not passing through have more than 255 triangles in geometry?
I am Assuming you have set your Collision Detection to Discrete In your gameObject's RigidBody, if so, please make sure to select Collision Detection to Continuous In your gameObject's RigidBody.
Reason Why this is not working
You are trying to use collision that has (speed > your Computer's frame speed) so, the frame is not catching the collider properly some time catches and some time fails to catch.
You are moving your GameObjects with tranform.translate or position etc. If so then make sure to use Rigidbody Related function for Positioning, rotating.
Solution Image For First Problem
I'm assuming
-you game object which contain the mesh component is very small ( bellow 0.7 size(x,y,z) so the game engine is little difficult to detect it)
and also
for the colliding objects at-least one rigid-body component must be attach to one object
This seems to be a common big problem, and I have been struggling with the same issue for days, and have finally fixed it, so am feeling like I should highlight one important thing:
move Rigidbody via MovePosition, not via just changing its position field directly, nor via changing position of GameObject holding it.
Changing position via "wrong" ways will "teleport" your rigidbody, physics won't fully work on it in that case.

cylinder simulation on top of each other in unreal engine 4

I created 2 cylinders and put one on top of the other. Then I clicked to simulate physics and on each cylinder I added the following image blueprint, added a 50-point rotation on the z axis of each cylinder in opposite directions.
It turns out that in the simulation, when I perform, the cylinders rotate in one direction and move on the ground in the other direction. If it turns clockwise it moves left, and vice versa, and should be the other way around.
Can anyone help me solve this? It's for both cylinders to work together and I see how their simulation is accelerating with a constant rotation, but that's not what happens
If you want to simulate physics you should be applying forces to the cylinders using Add Torque in Radians or Add Torque in Degrees rather than modifying the rotation directly.
Alternatively, if you want to precisely control the cylinders, do not simulate physics. Instead, disable Simulate Physics and animate the rotation and position of the cylinders directly as you are.

How to add reaction force to a collision in Unity?

So when using rigidbody physics on a 2d sphere and a spinning animated 2d rectangle it only pushes the sphere aside when it collides. What I'm wanting is the sphere to fly off when collided (don't ask if it's if it's a problem with it colliding or not).
I've tried the physics materials and adjusting the rigidbody and such but nothing works. There's not a single thing online about it so attempting to code physics would be very difficult.
If I understand correctly.
You could apply AddForce or AddForceAtPosition function with ForceMode.Impulse argument to sphere when Collider2D.OnCollisionEnter2D(Collision2D) event trigger.
Or Just modify sphere speed when Collider2D.OnCollisionEnter2D(Collision2D) event trigger.
Note that Collision2D have contacts and relativeVelocity which may help you calc the force vector.

SphereCastAll does not detect some collisions

I'm casting SphereCastAll in direction of the red line and I sometimes have a strange issue that this cast misses some colliders like in the screen below. The green line shows SphereCastAll origin and closest hit with different rigidbody to not collides with own colliders. SphereCastAll radius is half of car width.
Sometimes SphereCastAll misses all colliders from car in front and hits the next car.
Rigidbody is moving by WheelColliders
Here's a link
One interesting aspect of Physics.SphereCast() is that it occasionally fails if the sphere was already colliding with an object. Thus for Physics.SphereCastAll() it might not return the first (couple of) collisions if the sphere would already be colliding with them. Consider using Physics.OverlapSphere() to get the collisions you are missing or reducing the radius of the SphereCast to such a radius where the SphereCast cannot start inside of any other enemies / cars / what-have-you.