# Tag Info

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

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

How do you approach Canvases in Unity? It's possible to use more than one screen-space canvas in Unity, but it's uncommon. There is usually no reason to do that, unless you want different UI elements to use different basic canvas settings. If you want your game to support multiple resolutions, then you want to avoid absolute positioning. You usually anchor ...

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

4

Your problem lies in generating the graph, before any actual pathfinding takes place. It looks like you want the intersections of tiles to be considered the nodes of your graph, and only want intersections where all four adjacent tiles are ground. If you do it correctly, the pathfinder in your example will have only one valid path to choose from.

4

You would usually use the canvas for UI elements. You can anchor your elements relative to positions and it should take care of your scaling for different dimensions if done correctly. A gameobject and prefab are almost the same. A gameobject basically is a container of something. It can hold multiple scripts, your sprites, colliders, etc. Take a look at ...

4

Physics Try to think about what happens when a cannon ball traveling through the air hits something. The ball will have a certain mass and velocity, and thus a certain amount of kinetic energy that can potentially do damage. What happens with the cannon ball itself after a collision? Does it bounce, fall down, break apart, roll, catch fire or explode? It ...

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

3

Set the pickup to be on a layer that interacts with the ground only, not the player character. Give your player character a child object that represents their collection radius. Give it a trigger collider, and set just this child object to be on a layer that interacts with the pickups, leaving the root of your player character on its original layer. Now your ...

3

If I understand correctly, you want the algorithm to return a path that touches the center of each grid (the red dots, in your last image) rather than one that goes along the grid lines (the blue line, in your last image). To accomplish this, you need only to add the half-size of your node to the node's world position. For example: Given a node whose grid ...

3

This problem is just begging for Newton approximation like recursions. How to find distance of arc up to precision required? First iteration: Find out the distance between both endpoints. Create new points at 1/4 of a distance from 1/4 first control point to 3/4 of second control point, plus 3/4 of a distance from 1st point, plus 1/2 the distance. Measure ...

3

An EdgeCollider2D would handle this case well. Much like a LineRenderer, you provide it a list of points to join into line segments, marking your collision boundary. It can be a closed shape, but it is not required to be closed.

3

You can do this more simply by having one coroutine that expresses the sequence of actions you want to perform: IEnumerator MovePauseAndReturn() { yield return MoveTo(targetPos); yield return new WaitForSeconds(1); yield return MoveTo(origPos); } And a workhorse that performs the move: IEnumerator MoveTo(Transform destination) { while (...

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

2

Thanks to @DMGregory, the solution for anyone else with the same question is as follows: Find the sprite in your project Open the sprite editor from the inspector Edit the collider If you don't set any collider here, it appears Unity will figure it out for you instead.. which in my case was not appropriate. I just made my collider into a box.. as follows: ...

2

You'll track two separate position variables here: your current on-path position, and your current actual position, shifted from the path. Store your offset from the start of the path when you first begin traversing: waypoint_index = 0; path_position = path.get_waypoint(waypoint_index); offset = actual_position - path_position; When you update your path ...

2

So after much effort I finally get it working, although I'm not sure if I did it the best way. Tried to do what Agent Tatsu suggested but it didn't work. I did something based on what I understood from the BlueRaja's answer. Basically I took every walkable tile of the map and "packed" each with its three adjacent tiles to form a "bigger tile". Each of these ...

2

Interestingly, if the player dies before reaching any checkpoint, the MoveTowardsPlayer scripts still works after respawning. It only stops working after any of the checkpoints are reached. Presumably your problem code is this: if (dist < sightDistance) theRB.velocity = targetDir * moveSpeed; When you respawn the enemy, you move it back to its original ...

2

It looks to me like your code is placing things in a grid that you've built in world space. The canvas scaler component doesn't help if your grid is in world space. Instead of manually creating a grid, use the GridLayoutGroup component. This component lets you easily create a grid on a canvas.

2

Disclaimer: talking from Unity game development experience. It is not about resolution... Base resolution has very little to do with responsive UI. UI elements can be up-scaled or down-scaled. Resolution pretty much only gives you sharpness (or more space if you don't scale your elements accordingly (would not recommend)). Personally, I choose 1920x1080 (...

2

SpriteStudio is an external software for 2d animation that Xenko supports back, I believe when it's own by Silicon Studio (I think it does make sense since Xenko is originally a Japanese game engine, and SpriteStudio is of Japan, too). I also know that fact from the documentation site, but can't find it anymore now (maybe Stride won't support it anymore?). ...

2

First disable the gravity of the objects rigidbody when it gets spawned. You can do that in the inspector of the prefab for your projectile, or you can do it with code. For a 3D rigidbody you do that with: GetComponent<Rigidbody>().useGravity = false; For a 2D rigidbody you do that with: GetComponent<Rigidbody2D>().gravityScale = 0f; When 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

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

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 w := (Power(r, k)...

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

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