Unity TileMap Grid problem with creating a simple fog of war - c#

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.

Related

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

Unity - How to mask sprites inside sprite mesh?

I'm trying to animate a face using Anima2D for rigging.
Anima2D generates Sprite meshes for sprites that would be rigged and animated.
My problem is that I need to hide the tongue and teeth inside the mouth, and for that I was using sprite masks which are static and don't deform.
Is there a way to use sprite meshes as sprite masks? Or is there any other solution that I can use?
The image is an example of what's happening when I move the mouth (which uses sprite mesh). As the sprite mask (marked in orange) don't deform, the teeth and tongue bypass the mouth.
PS: I've found about stencils, but I don't think they would work since I need to hide sprites inside sprite mesh (not normal sprites).
In general, you would just need to change your "mask interaction" setting on the SpriteRenderer component on your tongue and teeth gameobjects and play around with the "Order in Layer" or "Sorting Layer" on these objects as well. Here's a quick example of what I quickly put together. Note the highlighted area:

3rd person controller, allow camera through wall and prevent player

im working for 3rd person fighting game between two characters.
I've setup camera to focus enemy and player in same time like Naruto Ultimate Ninja Storm 4, but when camera collide with wall the view angle will be change and both characters will not appear on screen.
in Naruto Ultimate Ninja Storm 4 there is transparent wall around arena which leave empty space between visible object (wall,rock..) and player but allows camera to pass it.
my problem I don't find method to let the camera pass this transparent wall and stop player to pass it.
I tried to get tag of object in collision and disable collider of object when is camera or vice versa but that allow character also to go tought transparent wall
You should create 3 layers, if you haven't already:
Player
Camera
Wall
Put each GameObject in the corresponding layer, then go to Edit->Project Settings->Physics, scroll to the "Layer Collision Matrix" and uncheck the collisions you don't want to have. In your case, you want the collision between the wall and the player, but you have to uncheck the collision between the camera and the wall.
Also, to make this work correctly, make it so that none of the characters, walls, and camera are separate gameobjects.
This is also very useful to remove any unnecessary collision and boost your game performance.

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

XNA 2D Game Camera doesnt work

I'm making a zelda-like 2D Role-Playing-Game with XNA and wanted to implement a camera which follows the player today. Soo... I didn't really understand how it's working, but I found a nice code-example here: http://www.david-amador.com/2009/10/xna-camera-2d-with-zoom-and-rotation/
I implemented it and changed the spritebatch.Begin(); to what the guy in the thread said. Now it is working ... well. The collisions are alright and the player is centered (since I set the position of the camera to the position of the player once a frame) but: The textures don't get drawed the way they did before. So for example the shadow is drawn under the grass (=you can't see the shadows) the player is sometimes drawn over the NPCs and sometimes under them and the wall-tiles disappear and reappear like they want :(
Do I have to change the drawing-code or the order they get drawn?
Hope somebody know what I am doing wrong...
In your Spritebatch.Draw call you can specify the layer depth. When specifying the layer depth, you will need to use the proper Sprite Sort Mode when initializing your SpriteBatch.

Categories

Resources