Unity player boxcollider 2d Contacts Normal Vector bug - unity3d

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.

Related

Unwanted bounce on edge

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.

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.

Unexpected trajectory after a collision

I'm currently trying to develop an arkanoid-like game in Unity but I'm having a problem that I can't seem to be able to solve with a satisfying solution.
When the ball hits the edges of two adjacent bricks, it "reflects" the velocity in an unexpected way: the ball goes to the direction where it was coming from.
For information, I have a world space size of : 5.625x, and each brick has a size of 0.703125 for 8 bricks per line. Also, every bricks have the same Y size for the collider.
I tried increasing the x size of the collider to some reasonable extent (0.74x for example) to make sure there's no gap between two bricks but the problem still occurs sometimes.
Here is a very ugly picture illustrating what's happening (the green arrow being the expected trajectory):
Thanks in advance for your help!
EDIT: Here are the inspector informations regarding the ball and the bricks. Regarding the lines of bricks, it's basically eight game objects with a boxcollider2d and a kinematic rigidbody2d.
The ball material has a friction of 0 and a bounciness of 1.

Unity: fixed Y axis of prefabs

I am building a top down shooter using the unity survival shooter assets. The problem I face is that all of the spawnable prefabs(enemy, player) have a fixed Y axis position. This is sometimes causing them to float in places where the ground level is low and sometimes they will sink where the ground level is higher. They do not change or update the Y axis as the terrain does.
How can I fix this so that the prefabs move according to the terrain.
Enemy Settings
PlayerSettings
Scene Screenshot
Terrain Navmesh
I would recomand you read this: http://answers.unity3d.com/questions/197952/rigid-body-and-character-controller.html if this doesn't solve your problem,
first I would try to play around with the mass and angular drag. Second of all I would rebake the nav Mesh. Third I would change the slope limit and step height and rebake again. And last I would try to use agent.updateposition = true; and agent.updateRotation = true;
I hope at least one worked. Happy coding !

Unity 5.2 - Moving character bumps between 2D edge colliders

I'm creating a fast-paced, 2D side-scrolling game on Unity 5.2, building my terrain out of discrete "blocks", each with its own EdgeCollider2D component.
Having a problem where my character gets bumped upward as it crosses from one block to another (imagine driving your car over a speed bump on the road).
This doesn't happen all the time. Seems to be random, which is even more irritating, as it makes finding a solution more difficult.
I've tried all of the suggestions that I could find for similar questions on this site, including:
Using CircleCollider2D's on the character
making sure the terrain blocks and their corresponding colliders are perfectly aligned. The attached screenshot shows one of the intersections.
changing the "Min penetration for penalty" setting to the minimum allowed value (0.0001)
switching between discrete and continuous collision detection for the character's RigidBody2D
increasing the mass and gravity scale for the character's RigidBody2D
... to no avail.
Beyond building a single, massive terrain object with a single edge collider from start to finish (which I'm trying to avoid), I've run out of ideas. Anything else I'm missing? Is it just a Unity bug?
Help!
Try detect the collision and set the vertical velocity to zero.
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.name.StartsWith("block"))
rigidbody2d.velocity = new Vector2(rigidbody2d.velocity.x, 0);
}