Hot answers tagged

28

This is Matt, the creator of Trainyard. @DMGregory summoned me here! :) It sounds like you're working through the same issues I had to deal with. It's a tricky problem where there isn't necessarily a perfect solution. One thing to consider is the constraints of the problem. I was targeting a 50mm wide screen on the early iPhones, and Apple's recommendation ...


17

We can do this by making a custom version of the standard sprite shader (so it still does everything the one you're used to can do), and modifying its blending operation. Start by going to the Unity Download Archive, and grab the built-in shaders for the version of Unity you're using. I'm currently on 2020.3.7f1 (LTS) Inside that zip, you'll want to copy ...


10

To handle a symmetrical object like a cube that could be photographed from many different directions, you could try comparing silhouettes: Render the quest object's silhouette and match that against the current camera view. Create the quest Use a render texture, set your camera to clear with transparent and to only renders that one object, render. Convert ...


6

I think you can solve the two pain points you indicated with a few heuristics. One is a little hysteresis: once the player is drawing in a particular row/column, keep their drawing cursor locked in that row/column until their mouse/touch point strays more than ~30% of the way into the next row/column. That gives more tolerance for error, so the player has ...


5

One approach is to simulate natural growth of a real village. Looks good and organic. May be iterated to expand forever. Easily adopts to existing terrain (rivers, forests, cliffs). Start with a house in the middle of the area. These are your first settlers. Choose a building type that is most needed next, considering what was built already and what is yet ...


5

I would say it depends a lot if you have one spot for every "photo" or if there are several possible place where the photo could be used. If you got one spot for every photo, you can simply check for the coordinates and the players viewing direction. Than you can add some tolerance to both and that should be enough. But if you got several places ...


4

There are no right or wrong ways to do things. Only ways which work for you or don't work for you. There are several competing philosophies in mainstream game architecture. A: Object-oriented architecture Every entity should be represented by an object. Those objects should contain all of their own logic, encapsulate their internal state and communicate with ...


4

For a smooth loop like this, we want to scale the camera viewport from 1 x at the start to \$r\$ x at the end of the first loop (where \$r\$ is the ratio between the inner image size and the outer image), then \$r^2\$ x at the end of the second loop, \$r^3\$ at the end of the third loop, etc. A function whose value compounds by some ratio each time we move a ...


4

Rule based placement This approach will probably need revising once you start having more different building types and rules to their placement, but the task is assumed to be exactly as specified and should be able to expand somewhat as needed: List of fixed building types as input. Each building type comes with a set of rules for placement. Buildings are ...


4

Open Unity On top of Unity window, you will see your version number. Will look something like, Unity 2020.3.8f1 Go to: https://github.com/Unity-Technologies/2d-extras On Unity 2d Extras Github, check to see if your Unity version above matches the current branch. If you're unsure, do Control + F and search the word Branches to find the branches link on Github,...


4

For example, another player stuns or slows down you, on the server, you will be slowed down or stunned There is a delay there, from when the player initiates the stun until it reaches the server. For the player initiating the stun, it does not happen right away. If we do not deal with that lag, it will bite us later. Let us follow the general approach: Send ...


3

Can this strategy work at all? Yes. Thus, I will answer a different but related question: How can we build up to that strategy? I will cover most of what you ask. Except one detail: ECS. Why? it is a detail. Base architecture Go back to the original conception of object oriented programming. The way Alan Key expressed about it. Objects are like little ...


3

By doing a preview with time increments different from your process, you're bound to have differences. For example, consider these extreme cases: You simulate a preview with 1 point per second: on the first step, your Yvelocty becomes -500 + 300 = -200, making it as if you started your jump with a speed of only 200 while it should be 500 in reality. You ...


3

If you need to wrap just a few steps out of bounds (up to negative size), then you can do this like so: (size + coordinate) % size When coordinate = -1 then this gives you (size - 1) % size = size - 1. And when coordinate = size then this gives you (size + size) % size = 0. For any value in between (0 to size - 1), this behaves the same as the identity ...


3

This might look different depending on the tools you are using, but here is how I would approach this. Getting the Texture In the scene where the place of the photo exists, create a camera object, that is only available to you (and other developers), but not the end user. When needed, take a screenshot of what that camera sees, and use that as a 2D texture. ...


3

It depends on how much you want framing the shot to count Basically, there are two ways you can look at this problem. You can either treat the player as someone trying to exactly recreate the scene from the photo, or you can treat it more like a scavenger hunt where the photo is just a "thing" you need to find. If you want the player to have to ...


3

To start with, we need to break down what is meant by room or cave. With respect to the 2D array in the problem description, a room is a collection of elements that are 'connected'. For any given starting point, we can identify all the elements of a connected region using a flood fill algorithm. The flood fill algorithm presented below works as follows: tag ...


2

I don't know if it will helps you but, I had a similar problem. I resolve it by adding a border to my assets in "TexturePacker". You just have to open the "Advanced Settings" And at the bottom, just add a border padding of 2 pixel as it recommended. It should help you =)


2

The downside is that you will have to load the entire spritesheet. When you load level 1, you need to load the entire sprite sheet that contains even a single asset on it from level 1. This means you will be loading all of the sprites for level 2, 3, 4, and 5 as well. If you were to have a separate sprite sheet for each level, you only load the sprites ...


2

Have a look at ray casting. The simplest approach is to cast rays from the center, which gives a reasonable approximate answer: A more advanced & precise version would only at angles where the walls begin or end: The above examples were taken from this tutorial on 2D visibility from Red Blob Games. Best performance will be achieved with WebGL. In my ...


2

given the tileset I have, is this the most efficient way to obtain what I needed? Yes, stacking multiple layers of tilemaps is a tried-and-true method which is being used since the 16bit age. But since they are on two different tilemaps I cannot use a composite collider to optimize the collider's layout. That's incorrect. You can merge the ...


2

If your only requirement is plotting out a thicker line of river tiles along a path of points, you can simply do the following: To get a river of width w then for each (x,y) position along the path: for(Point p : path){ for(int a=0; a<w; a++){ for(int b=0; b<w; b++){ mapTile[p.x+a][p.y+b] = river; } } } This is a brute force ...


2

Here is my solution based on the answer given by DMGregory. This is Delphi Pascal. The LinearInterpolate function is just a lerp. Care has to be taken to avoid divide by zero. CamT.Scale := Exp(LinearInterpolate(Ln(Cam1.Scale), Ln(Cam2.Scale), k)); if abs(Cam2.Scale - Cam1.Scale) > 0.001 then begin r := Cam2.Scale / Cam1.Scale ...


2

I would recommend you to structure your project a bit differently. Instead of having the Respawn script on the player (I assume it's on the player) detect and handle all the interactions with different objects in the world, you should make those objects themselves responsible for detecting the player and triggering a response from it. So first of all, don't ...


2

The problem is that Unity allows you to put your Counter script on as many gameObjects as you want, and each one would have an own ScoreAmount. So Counter.ScoreAmount is ambiguous. Unity doesn't know which one you mean. So how could you fix that? Solution A: Make ScoreAmount static. When you declare a variable as static, then all instances of that script ...


2

Even though the map is "small" at 100x100 with two layers, that's still 20,000 draw calls per frame. One optimization is to only draw the tiles that are visible such as limiting your camera's viewable area and zoom levels so you can't see more than a few hundred tiles at once. You'll have to implement the ability to query if a tile is visible to ...


2

With the following assumptions: You have a maximum number of building of each kind to place. You have adjacency rules (such as: House can be adjacent to House, Church and Factory; Church can be adjacent to House; and Factory can be adjacent to House and Factory). You can do this (explanations in comments, ugly details to make it work in JavaScript at the ...


2

the accuracy should be in 1-2ms intervals You are out of luck here, getting high and steady frame-rate in WPF is impossible by design. Still, you can get decent 60Hz, and anything above requires high-frequency display anyways — I expect those to be rarity in a business environment. I am planning to use writeable bitmap 800x40px. D3DImage should be a ...


2

So I figured out a solution. I basically check the previous direction I got from my function (without rounding it) and check the angle with the new direction my sprite wants to go (without rounding it) by doing Vector3.Angle(previousVector,direction) and then verify if the angle is greater than 30. If it is, I change the direction. If not, I keep the ...


2

If we venture down to the Godot source code, on Polygon_2d.cpp we find how polygons is used (here). Godot expects the array to contain arrays of integers. Reading the code we can also figure out that they are indexes (0 based) for the points. So, let us try that. We create a Polygon2D on the editor, give it a set of points, and then in the polygons property ...


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