Walking up and down 2d slopes (pixel art) - c#

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).

Related

Unity TileMap Grid problem with creating a simple fog of war

I have a procedurally generated dungeon BSP on a Tilemap Grid. a TileMap collider has been added to it.
I planned to do it simply, since my TileMap contain a SpriteRenderer, I add the color 0,0,0 to it like a black fog of war, and if I can't see it well or have already opened it i would repaint them with 0.5,0.5,0.5, and the area around the player would make 1, 1, 1. and that would be cool, BUT I only can get tiles from the map via VectorInt, or via an index and a copy of the array. Can I access each cell, somehow through a collider? To use something like Raycast or Overlap Colliders.
any collider or collision tells me about the TileMap map. Or do I still need to create each tile and attach them to a game object or Scriptable object? I'm confused, tell me, I reviewed many tutorials and questions on this issue and got confused
I don't completetely understand, but I'm pretty sure you want to add a tile during runtime? Or you at least want to change the tile so that it's black or has a fog of war?
First off, I found this link: How can i place a tile in a tilemap by script
However, that would be difficult, having to have some kind of array, or possibly 2d array, of all the tiles for when there shouldn't be a fog of war.
My suggestion is using a Sprite Mask , and setting the tilemap(the actual ground) to not interact with the mask, and having a big fog of war sprite, like a big black cloud that might follow the player around so that it doesn't need to be a massive sprite, and set it's sprite interaction to visible outside mask.
Finally, make a sprite mask that follows the player around, and therefore will remove the fog of war around the player.
Another thing is to make a big cloud sprite with a hole in the middle, and have it follow the player around. That way, there's a big fog of war, but there's a hole in the middle so the fog is not around the player.

Unity 3D Character Stuck on wall-colliders

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

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.

Rotating faces Rubik's Cube C#

I've been looking around the internet for a few days now, and I can't really find an answer that i can understand well enough to rotate my Rubik's Cube.
I have made my own 3D Model using Blender of a Rubik's Cube and imported it in to Unity which is what I'm going to use to rotate the faces.
But I just don't seem to understand the mathematics involved in rotating a Rubik's Cube, should i use Matrices? If so how do i couple it all together for it to work?
I can rotate a single side around by grouping the bricks together by faces, but the moment you turn the next face it would completely disrupt the other one.
Thanks a lot!
My idea: Keep each of the 26 blocks as separate GameObject objects (8 corners, 12 edges, 6 centers), with each block's origin in the center of the cube. Separately you keep track of which block is currently where on the cube, for example in a 3D array.
Then when a face needs to be turned:
Find out which blocks belong to the face.
Rotate each of those blocks around the axis of rotation (through the middle of the cube) using Unity's normal rotation functionality.
Update the information on which blocks are where.

How would I go about converting my 3D maze to a 2D maze?

What I want is sort of like a mini-map. I've already constructed my algorithms for both the 3d maze and the 2d maze but I would I'm not sure how to convert the 3d one in a 2d equivalent. Here's my code my code from gist.github.
You can take a screenshot of a plane going through the current level the player's at and paint obstructing polygons black and the rest leave white. But first you would need to cut out all intersecting areas from that plane. Not sure you can do it easily enough in-game with XNA.
I bet it's easier to do manually in a 3D editor by removing all but current level and making a huge screenshot, saving it as that level's map, although if you're going to rotate the cube in all directions, you'll need to do that lots of times.
One other approach is to make a mini-copy of entire map divided into 3d matrix of cubes and draw desired 2d array selection.

Categories

Resources