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.
Related
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.
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.
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).
I am currently working on a 3D Unity game in which you control a block through a labyrinth made out of blocks and have to avoid spikes, moving enemys and other traps.
Here a picture how it looks at the moment ( you are the blue cube and have to avoid the moving pink ones ):
The problem now is, that when I move along a wall, the player gets stuck and stops moving until I move in the other direction again (every part of the wall is as big as the player because I am generating it from an image).
I already tried everything with Physics materials and friction but it does not get better :(.
The problem is that your BoxCollider of the player is probably getting stuck on the edges between two of the wall colliders. Consider "smoothing" the edges of the collider a bit so the player wont get stuck.
The default collision detection mode in Colliders is Descrete, it might jump through a small gap occasionally, you could set the players collider to CollisionDetectionMode.Continuous it will prevent the overshoot.
Try decreasing the Default Contact Offset in Edit/Project Settings/Physics
Changing it from 0.01 to 0.0001 worked for me
Source
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.