11 votes
Accepted

How to use the SDL viewport properly?

My guess is you're trying to implement a camera, and should not be using SDL Viewports. The viewports are for UI elements like menus, minimaps, etc. It's a way of dividing up the screen into multiple ...
amitp's user avatar
  • 6,046
10 votes
Accepted

Is a custom coordinate system possible in Unity

If what you want is to bypass the floating inaccuracy caused by single point precision problem, for the sake of creating bigger environments for your game, then it depends on what you are willing to ...
MAnd's user avatar
  • 4,907
9 votes

Overcoming float limitations for planet-sized worlds in Unity

That's a question that frequently pops up. I will take the liberty to forward you to another fairly detailed answer I already gave to the same issue, instead of just repeating it here: Is a custom ...
MAnd's user avatar
  • 4,907
8 votes
Accepted

Get local coords from global coords

The point P to be transformed is, in homogeneous coordinates: $$ \begin{pmatrix} 50 \\ 40 \\ 1 \end{pmatrix} $$ The homogeneous transformation matrix M is (using \$cos(\frac{\pi}{4}\$) = sin(\$\frac{...
Pieter Geerkens's user avatar
7 votes
Accepted

Overcoming float limitations for planet-sized worlds in Unity

You're thinking in very static terms. Just because an object is half a world away doesn't necessitate any issues. If entity coordinates are stored relative to chunk rather than relative to world, ...
Engineer's user avatar
  • 29.4k
6 votes

How can I randomly generate objects inside of a Complex Area?

Triangulate the area. Pick a random triangle. Generate a random point inside that triangle (link).
Tin Rabzelj's user avatar
6 votes
Accepted

Finding all hexagonal grid coordinates inside cover arc

I prefer to do hex-cell coordinate math in what Amit calls cubical coordinates on your linked page. For the rest of this answer, (X, Y, Z) will refer to cubical coordinates. Basically, for any of ...
Jimmy's user avatar
  • 9,029
6 votes
Accepted

How to raycast down to the floor plane to determine world space coordinates in Godot

I'm not sure I understand your limitations, so I will give you a few approaches, and hopefully this gets you to the solution along the way. This is not an exhaustive list. Pickable Object If you have ...
Theraot's user avatar
  • 25.2k
5 votes
Accepted

Finding a tile number in a grid system

The only way I know of, or at least can think of right now, is the following: Prerequisites: You need to know the width and height of your grid the tile numbers must increase successively, so like ...
Throzen's user avatar
  • 163
5 votes

Convert quaternion to a different coordinate system

Summarizing your two coordinate spaces: ...
DMGregory's user avatar
  • 132k
5 votes
Accepted

Handedness of 2D coordinate systems

It entirely depends on what you want to do with it and both have reasons why they exist. The one where the top left corner is the origin and the positive xes point away from them are based on the way ...
Bálint's user avatar
  • 14.8k
4 votes

Is a custom coordinate system possible in Unity

I doubt that there's a way to change the coordinate system Unity uses internally for its transforms/physics/etc. Not without recompiling the engine source at least. But that may not be necessary to ...
DMGregory's user avatar
  • 132k
4 votes
Accepted

LibGDX Overlay Game with Stage

You need to project from the worldspace to screen space using the correct camera, not the project method on the Vector2. Then ...
bornander's user avatar
  • 4,461
4 votes

How can I randomly generate objects inside of a Complex Area?

This might not be the most elegant solution, but it might work for you: Define that shape as a PolygonCollider Get the bounding box of that collider (...
Philipp's user avatar
  • 118k
4 votes
Accepted

Why does the Debug.DrawRay return these weird lines

You're drawing Rays, not Lines. This means that the second parameter is a direction not a point in space. https://docs.unity3d.com/ScriptReference/Debug.DrawRay.html Draws a line from ...
Draco18s no longer trusts SE's user avatar
4 votes
Accepted

How to convert a 4x4 matrix transformation to another coordinate system?

This is as easy as writing your old coordinates in terms of the new ones. We want +x to map to +x (1, 0, 0) We want +y to map to +z (0, 0, 1) We want +z to map to -y (0, -1, 0) We want the fourth, ...
DMGregory's user avatar
  • 132k
3 votes

clamp a 2D coordinate to fit within an ellipse

Here's a general method to clamp a point \$A\$ to the ellipse of center \$C\$ and half-dimensions \$d\$ (i.e. the ellipse is \$2d_x\$ wide and \$2d_y\$ high): \$B = \frac{(A - C)}{d}\$ gives you the ...
Quentin's user avatar
  • 1,168
3 votes

Overcoming float limitations for planet-sized worlds in Unity

Not sure if you have already settled for a solution, but I'd like to mention two other resources that might be useful to you and other readers in the future. This recent CppCon talk: "Demystifying ...
glampert's user avatar
  • 3,057
3 votes

how to create an outlined polygon with vector3 coordinates?

1)Find barycentric coordinates for(int i = 0; i < verticesInPolygon; i++) { bary.xyz += vertices[i].xyz; } bary.xyz /= verticesInPolygon; 2)Create new ...
Ocelot's user avatar
  • 1,423
3 votes

How do I get the 3d coordinates of my model Instance? [LibGDX]

Try something like: Vector3 position; position = modelInstance.transform.getTranslation(new Vector3()); This gets the position and stores it in the ...
Charanor's user avatar
  • 7,800
3 votes
Accepted

How do I convert positions between local coordinate systems?

What you have is the basics of 3D math, without any rotation. In 3D, we generally refer to an object's position as its translation, and set of things that describe its position (its translation, and ...
Tom K's user avatar
  • 1,319
3 votes
Accepted

Calculate position on Isometric grid

Looks like you want: ...
DMGregory's user avatar
  • 132k
3 votes
Accepted

Convert global 3d coordinate system to a local one with specific direction

Construct a matrix like so, where each vector is one column of the matrix: [ House's X+ direction | House's Y+ direction | House's Z+ direction | House's position] The fourth row should be [0, 0, 0, ...
DMGregory's user avatar
  • 132k
3 votes
Accepted

Alternatives to Camera.main.ScreenToWorldPoint in Unity

Basically, when you call Camera.main, Unity internally uses the FindGameObjectsWithTag to search through all of the objects in ...
Sean Carey's user avatar
3 votes
Accepted

How to invert a Tilemap's coordinate system?

It might be smarter to work with unity instead of against it and just accept how its coordinate system works. Keep in mind that this coordinate system follows the same "y is up" logic as the Unity ...
Philipp's user avatar
  • 118k
3 votes

Algorithm to check whether pizza toppings are divided half-and-half

After getting help from @DMGregory I was able to solve this by : Getting the center of the toppingsA and toppingsB Finding 6 most far toppings from the centers generate 2 polygons based on these 6 ...
A.J's user avatar
  • 151
3 votes
Accepted

Ensure that random enemies don't spawn just near the player

The simplest system I can think of consists in testing the position of the new enemy before your screen.blit(), like so: ...
Sisyphe's user avatar
  • 66
3 votes
Accepted

LookRotation function for Z-up, right handed system

First, we can transform your coordinates into Unity's coordinates: ...
DMGregory's user avatar
  • 132k
3 votes

Should the coordinates, and rotation angles of all the sprites be stored in variables?

Storing values in variables is not the same thing as using magic numbers. The magic number anti-pattern is a direct usage of a number in the code. For instance, compare the following code snippet: <...
Pikalek's user avatar
  • 11.5k

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