A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

Hot answers tagged

8

It's a palette. Same thing you see some artists doing with colors. They draw a group of a couple of the main colors or even a gradient going between them for easy access. It's much easier to use a picker tool to select the next color than to go into the color picker wheel, fiddle around with it for a couple of minutes and pray it matches the rest of the ...


8

I don't know if there is a name, but this seems to be something you'd do to conserve memory. First, a basic tile is very low resolution - just a few pixels across. But when rendered, they are magnified 2x, 3x, 4x, etc. and are much more "blocky" on the screen. Next, older games will have a block of memory dedicated to screen display - what is in that ...


4

First fix your A* implementation so that it will find the shortest path. Adjust the cost of the turn instead of the heuristic. This means that when you generate the neighbours the one going straight ahead gets cost 1 and the one where you make a left or right gets a higher cost depending on how large a detour you accept. This means that every tile can get ...


3

I arrived here by Googling this problem myself, read the linked articles, and produced a relatively compact solution which generates the common set of 47 tiles. It requires a 2x3 tileset for the autotiled material like this: With a single-tile variant at the top left, inner corners at the top right, and four outer corner tiles at the bottom (you may ...


3

After trying to write a code that merges the squares effectively (especially for large Tilemaps) both horizontally and vertically I decided to look if there is a better suited collider than the PolygonCollider2D which I've been using. Then I stumbled across a certain component and now I feel really stupid... The trick to avoid the problem I mentioned in my ...


3

I remember Unity guys explaining that each tile of the same type is not a separate instance. Instead the tile system visualizes literary the same tile multiple times. This is a necessary limitation to achieve decent tilemap performance. There is a GitHub repo at Unity's profile called 2d-extras. It contains a system called GridInformation that allows ...


2

I forgot to put a circle collider on the red circle. Leaving this up for others who might run into the same problem.


2

For anyone coming later for this question: Can I use customized Tile to store stats per tile? The answer is, No. If you define: public class MyTile : Tile { public float health = 3; } The value is shared among all tiles. It's design for the performance purpose - all tiles will share same attributes and render it multiple times. The solution I used is ...


2

There are 2 ways to change a tile's sprite during runtime: Change tiles in a tilemap to a new tile (SetTiles or SwapTile) Change tile's sprite Both solution requires re-rendering of tiles. This is why simply setting tile.sprite to a new sprite is not enough. I'll explain it later. Tile is only a reference to some attributes. Tiles implement some ...


2

The game world of Awake/Start/Update, and the physics world of PhysX, are actually two separate sets of data. It takes some extra work from the engine to apply changes from one world to the other. Normally this is done once in the physics step for each FixedUpdate, but depending on frame timings, we might not get a physics step / FixedUpdate in the frame ...


2

Have you considered using the contactpoint2d? It gives you information about the contact point where the collision occurred. Here is a demo code grabbed from 2D tech demo on tilemap. void OnCollisionEnter2D(Collision2D collision) { Vector3 hitPosition = Vector3.zero; foreach (ContactPoint2D hit in collision.contacts) { hitPosition.x = ...


1

instead of pathfinding on the centers of the tiles, pathfind along the corners and edges of the tiles. A corner is valid if all the neighbouring tiles are valid according to your existing algorithm(n-1)


1

If you want to keep things simple, I would pick a format and stick to it. The two most simplest image formats that I know of are: PPM BMP TGA It's not that difficult to implement loading of any of these files. I see PPM files used a lot in ray tracing examples because the file format is so easy to handle. If you're the one generating these images, I'd ...


1

I think this is more an opinion-based question but here are my thought (I'm not a C++ expert): Create a base class Tile that will handle generic stuff like rendering, animations if any, behavior of the tile... For each of your special tiles, create a new class that inherits from your base class Tile and override the behavior if your new tile has a custom ...


1

From generative code, if you have less than 100 levels, you can save the levels as unity assets / prefabs and load them instantly using a bit of scene management, level code and choose the 100 best that you prefer. If you have an animation of a level transition, which rewards the player, it can give you a few moments for him to chill out while you do the ...


1

Perlin and Simplex noise are both forms of gradient noise, meaning at each corner of a grid, they pseudorandomly choose a gradient vector that determines the rate of increase of the output value in the neighborhood of that point. So you can use this to establish an upper bound on how much the output can increase over a distance of one heightmap cell, ...


1

You already mentioned the two broad solution categories. Here are some specifics about each. Capping the values as they are generated: The potential problem with this is that depending on your implementation, you need to be careful about checking values before they are assigned. For instance, the very first value generated won't have any neighbors yet. Also,...


1

You can design each event room on a separate tilemap and then save that tilemap as a prefab. Those prefabs can then be referenced by ScriptableObject's or directly by the script which does your dungeon generation. If your architecture allows for more than one tilemap, then you could simply instantiate the event rooms. This would have the advantage that the ...


1

"Pack all the individual Sprites that make up the Tilemap into a single Sprite Atlas to solve this issue. To do this: Create a Sprite Atlas from the Assets menu (go to: Atlas > Create > Sprite Atlas). Add the Sprites to the Sprite Atlas by dragging them to the Objects for Packing list in the Atlas’ Inspector window. Click Pack Preview. Unity packs the ...


1

I suggest you to read about the vertex input layout and geometry shaders. In general: define your goal first, let's say the goal is to use only one draw call and least vertexbuffer updates because you want to keep the gl calls to a minimum. first calculate the uv coordinates for every region in your texture atlas and store them in a hashmap in ram. Then ...


1

If you want the map to appear as close as possible to what you've written above, without a lot of nulls to type out and clutter reading, you could define a helper variable first: var _ = null; var tileMap = [ [5,3,_,_,3], [_,1,0,2,2], [_,_,_,_,_], [5,_,_,2,_], [_,_,_,_,1] ];


1

After a while a found an answer. So the Tilemap instances have its own origin position in their parent grid object which can be accessed with <Tilemap instance>.origin. The origin position is equal to its minimum bound point after you compress the tilemap's cell bound. So you can get the exact center world position of each tile in a tilemap by ...


1

ok so i solved it by using shuvro's code along with some stuff added in Tilemap tilemap = GetComponent<Tilemap>(); Vector3 hitPosition = Vector3.zero; foreach (ContactPoint2D hit in collision.contacts) { Debug.Log(hit.point); hitPosition.x = hit.point.x - 0.1f; hitPosition.y = hit.point.y - ...


1

If I remember correctly, the tile coordinates are based on the lower-left corner of the tile, so if you called this method on (1,1) you might expect that to be within tile (0,0) but it's the next one up and over. That may be accounting for some of your coordinates being off. More importantly, your loop is creating a Vector3 starting at (-15,-15) but that's ...


1

Two things: Using LateUpdate instead of FixedUpdate might be the culprit - try FixedUpdate. It may also be related to the box collider on your players character - try sphere/capsule colliders instead.


1

The coordinate system you've chosen is not a Cartesian plane. The axis x=0 forms a zig-zag instead of a straight vertical line, because you've shifted the start point of alternating rows. Vector2Int ToJaggedRow(Vector3Int isometric) { int row = isometric.x + isometric.y; int column = isometric.x - isometric.y; // Shift alternating rows by one. ...


1

If you want to ensure that your players have the most up-to-date map possible, I'd start by including a version-header within each of your map files. This doesn't necessarily need to be a header per-say, it just needs to be some marker or value stored within the file that affects nothing about it in terms of game-play, but can store a value with the version ...


1

Just download this script AnimatedTile and put it into your project, then you can find AnimatedTile at Create > Tiles > Animated Tile. In case you don't want to click the link, I copy the script for you using System; #if UNITY_EDITOR using UnityEditor; #endif namespace UnityEngine.Tilemaps { /// <summary> /// Animated Tiles are tiles which ...


Only top voted, non community-wiki answers of a minimum length are eligible