Avoid the character jumping because of capsule collider - c#

My unity game have a character with a capsule collider. When the character hit another collider on the spherical part of the capsule, the character is send in the air. How to avoid that?
Here is a video to explain the problem
I already have some solutions but it doesn't really work:
Use a cylinder collider instead of capsule, but it doesn't exist. I tried to make one with meshcollider and the result is not as good as a caspule collider since the meshcollider is not perfectly rounded. I also tried to make one with many rect collider but it produce same problems as meshcollider.
Set a really big gravity force when the character is on the ground, but the problem is that I have inclined planes in the game, so it doesn't work neither.
Thank you for your help

I might not be right but I think you should delete the capsule collider and add a Mesh Collider or you could also just add colliders to each part of the player which would take longer but I think that's what you're needing. So add sphere colliders to the head, box colliders to the arms and etc.

You can propably fix the unwanted behavior:
with a different physics material for your colliders. Removing bounciness may help.
by adjusting scales of your objects.
by changing the collider of the ground from a box collider with sharp edges to a mesh collider with slopes on the edges.
by adding a code that will snap your character to the ground.
There is a great tutorial on character movement from Catlike Coding I can recommend: A series about controlling the movement of a character.

Related

How can I render contents inside a shape as a texture on the shape itself? As well as teleporting an object from one side of a mesh to the opposite?

I'm making a space game and I want the game to take place inside of a sphere or cube. I want the walls of the shape to render what's inside on the inside walls so it seems like endless space. Once the illusion of endless is in place I want to teleport the player if they touch the game space shape and teleport them seamlessly to the opposite side of the shape.
Edit: I just had an idea of how to teleport how I want. Maybe using ray casting to cast a ray behind the player and where ever that hits when they touch the edge of the shape to teleport to?
To answer question one I used a render texture. It's very close to the effect I want I just have to play with the perspective like they do with portals in portal 1 and 2.
To answer the my second question I went with raycasting. The player flys around in a sphere and casts a ray behind itself. Once the player hits the collision of the sphere they teleport to the point of the raycast. This works perfectly only for the fact when the player reverses on the sphere collider they escape the sphere flawlessly.

Walking up and down 2d slopes (pixel art)

I'm having an issue where I can't walk up slopes in unity. My art is pixel so I understand the slope is made with a gap of 1 pixel to create the actual slope, but I have no idea how to fix it so I can just walk up and down them normally. Currently, going down them makes it a little bouncy and going up them is impossible unless you jump. Any help would be appreciated! Here is what the slope looks like:
Edit: Collider looks like this but I don't know how to fix it:
Sprites automatically have a polygon collider created for them when imported into the project. This polygon collider drives the tilemap polygon collider shapes.
You can modify the physics shape for a sprite to smooth it out and remove this unwanted when going up a ramp. Custom Physics Shape documentation
Another important thing to note in your specific problem: Often when a character has a "box-like" shape, they will get snagged on edges and small collider deviations. Unless your game's playstyle is based around a box-shaped entity and interactions, it's usually recommended to use a rounded collider for the moving characters (like a 2d or 3d capsule collider).

Colliders not working in Unity3D 2D Project

I have 2 colliders, its a game where I have a ball, and a Labyritnh. The ball should pass through the labyrinth and collides with the labyrinth's walls.
But I have a problem, the physic aren't working that well, the collider don't work.
I have a rigidbody and a collider in both of these objects.
Also, I have a problem with choosing box or edge colliders.
Because it is a labyrinth, I need to design the colliders with some complex shapes.
I have used edges colliders and box colliders but the ball is passing through all these colliders like nothing, It seems like its not working.
Can someone help me?
you need a rigid body object attached to at least one of them for the colloders to work.
make each wall individually and use rectangel colliders. add a rigidbody component, and set that rigid body to kinematic. should work then.

Character gets stranded with polygon collider in sloped platform

I have used polygon collider for the hills and terrain like sprite in my 2d game.
I used the same polygon collider for my hero character. Here is my problem the movement is smooth when i used box collider in hills and all that but it makes my character look like floating in air. so i opt to use polygon collider for hills.
However polygon collider produces some small pit or irregular shape to fix the best possible shape of collider for hill. Here my player or hero get stuck in those pits or irregular shape. Even the slightest pit cause my player to strand. I tried various way to mitigate all those errors but no any result.
Please suggest to me some way to make my character movement smooth in uphill.
Instead of using one collider, try 2 different ones for your player. Put a box collider around his mid section and head, and a circle/capsule collider that goes around his feet. That way you get the circle/capsule collider will reduce the chance of your player getting stuck on awkward locations :-)
You can always try to edit the collider yourself, or even start with an EdgeCollider and make the shape yourself. Anyway, I don't know how irregular those "pits" are, but you can always edit in a very easy way the collider in 2D.
Oh, and you can edit the collider in the component itself, and then in the editor window.

Unity 2D line collider

I try to do the following: I have a point A at -4x-4y and a point B at 4x 0y. I want to make a colliding line from position A to position B.
I tried to do it with a linerenderer but I can't get the line to collide with my other 2d objects.
My other tought was to calculate the center of the points and the rotation and do it with a box collider but that seems to be really complicated and hacky.
Is there a simple way to achieve this?
Thanks in advance
You can use PolygonCollider2D, it's automatically create collider for sprites, and if you are not satisfied results, you can edit it by clicking Edit Collider in inspector, or trought Unity's API.
I think you must have a Rigidbody2D attached with your other 2D object. Then this will work 100%. You can use any collider it doesn't matter.

Categories

Resources