Unity 2D games, I have troubles with 2D collliders - c#

I have a lot of problems with some 2D colliders.
In the past, they work, but now they are horrible:))
I already try with Kinematics, OnCollision2DEnter, OnTriggerEnter etc.
The objects are already on the same layer, the same position on the Z-axis, they interact with each other but my game can't detect the collisions.
The rigidbody and collider don't have material but the objects have skins enter image description hereenter image description here

I've realized that the gravity scale of your ground object is above 1. You can make it 0 so it does not get affected by gravity. Gravity Scale is on your ground object's Rigidbody2D component right below angular drag. Although I could be wrong since what kind of collisions you are expecting and your movement code, that should help resolve your problems.

Related

2D unity platform game, conflict with Tilemap colliders

I'm trying to create a platform game, watching videos and tutorials I see that they use the Tile Palette option very frequently.
When creating the 2D Tilemap Collider, each square has its collider, and I guess that makes it consume a lot of resources, so to solve that I create a 2D Composite collider.
The problem is when the player collides with the collider of a vertical wall, causing the player's rigidBody.velocity.y to add force and that doesn't allow me to execute the jump.
https://clipchamp.com/watch/nFKCJOv7DEX
Here you can see under the scene of the game the debug.log that ends up showing me a speed to the Y axis
This project would be for android, and I would like to optimize it as much as possible. Do you have any idea so that in that collision I do not add force Y?
I have tried to change the speed in an onColliderStay2d and put the vertical tilemaps with another tag to differentiate them from the ground, but nothing.
Instead of checking your y velocity to see if you are grounded or not I recommend just making a rectangular area under your player character and check if it overlaps with the ground using Physics2D.OverlapArea. It's way less error prone.
Also, just because composite collider creates less shapes than tilemap collider doesn't mean it is less performant, the physics system doesn't iterate them one by one. Do yourself a favor and just use the tilemap collider instead.

Unity2D - Is there a way to make a 2d player not stick to walls without changing the physics material?

I started a 2d game and my character with a boxcollider gets stuck to walls (created with a tilemap so with a tilemap and composite collider)
I saw solutions to this where you have to put a physics material with no friction on the player, however if i do that it messes up other movements that use friction (such as a slide)
Is there a way to fix it without physics material?
You can put a physics material with low friction on walls instead of on player
or
you can write a script that when player collide with walls, push player away from wall a little bit depending on the normal of hit point.

How to detect collisions for a rotating child object in Unity3D C#?

I am making a First Person Shooter and I have a rigged player with a mouse look script, and I used to rotate the spine with spine.transform.rotation, but this method does not look for collisions, this means if I rotate and I am standing near to a GameObject, I glitch/bug through the object. So I tried to do it with a Rigidbody but this doesn't seem to work, I tried: rbSpine.AddTorque(new Vector3(mouseLook.y,0,0), ForceMode.Force);. This doesn't do anything. And I have another problem with the Rigidbody, I've only a rigidbody attached to the spine, my player has multiple simple collision and these overlap eachother a little, and my rigidbody is pushed away into the air slowly. Does anyone know a solution for this?
I put a rigidbody component on the player, this will take care of the collision detection for itself and all its child objects.

Unity3D Object 'Shoving' Mechanic

I'm trying to make a 2D top-down perspective game in which I want to try and implement a shoving mechanic as a way of the player interacting with the environment or even enemies, but I can't seem to nail down the physics behind it.
(Player object (P) and interactive object (O))
My Question is: what is necessary to make this work properly? I've tried a few things out, such as having the information to add the force to the Rigidbody2D on P first and then on O and I'm trying to get it so that the player pushes the object in the direction it's facing, which I have a script for transform.up to face the mouse. I did also try to implement a dash mechanic to see if it would push an object further, however the physics meant that P would dash in a random direction as opposed to being towards the mouse
give the player object a rigidbody and a colider and the object a colider, should work no problem then!
http://docs.unity3d.com/Manual/class-Rigidbody2D.html
http://docs.unity3d.com/Manual/class-BoxCollider2D.html
should just work automatically then, Unity doing all the physics work for you
edit
if you want the object to be more strongly affected just reduce it's mass int he rigidbody in the inspector, or increase the players mass

Collision between a sphere and floor is inaccurate in unity

This is the setup I have. I am trying to make a game in unity which appears 2d but is actually 3d. I have a simple sphere and a floor, which is made up of cubes placed next to each other(the colliders overlap a little) with the same Y value and Z value. My 2d plane is in X-Y plane(Z being the depth).
Now in the script attached to the sphere, in the Update function, I have used rigidbody.addForce() in the +ve X axis function to move the sphere forward. I have attached rigidbody to the sphere and enabled gravity. The collider of the sphere is the default one.
Now the problem is:
When I run this scene. The sphere moves forward but at the intersection of the colliders, it jumps a bit(very less but still noticable) upward and loses its momentum. It happens at every intersection.
BUT this does NOT happen if I place the sphere on a floor made up of a SINGLE cube(a very long one).
Is this problem arising because of overlapping colliders? How do I solve this issue?
Thanks in advance
I don't think this is fixable. Unity physics is approximate, and even when physics material are set up to 1.0 bounciness, momentum doesn't stay constant — I learned it the hard way when I tried to develop a game depending on constant momentum, and had to write my own little physics simulation for that.

Categories