Trying to understand collision and coordinates on a 2D plane

wize1wize1 Posts: 1Member
edited October 2018 in 2D

Could someone help me understand how hitboxes work? When I place tiles it's based on a grid, but the actual hitboxes can be scaled as a circle? I'm just a little confused how that works. The beginning of this video demonstrates the player moving in an 8 directional movement. So, what would happen when you encounter something diagonally?

as demonstrated in the beginning of this video

Also drew this to illustrate what I am thinking about. At what point does the engine recognize that the circle has entered the square?

I did a tutorial and all of these balls were interacting with each other as circles and the physics were working correctly. However I am still confused as to how a circle travels on top of squares.
So, imagine here that the green tiles are the map, and the blue circle is the player. How does the engine work in terms of determined at which coordination the player is, or if he is "touching" a square on the grid?

Would I need to study how coordinates and collision work in programming? If so, I am not sure where to look to study about this. Thanks in advance.

Comments

  • anomalocarisanomalocaris Posts: 10Member
    edited January 3

    Tiles are based on a grid, but any collision shapes you assign to an individual tile is based on pixels.
    Collision is determined as follows: if any pixel of one collision shape touches any pixel of another collision shape, they're considered to be touching. Movement is also pixel-based, which is why you can have a sprite overlapping multiple tiles at once. To have grid-based movement one solution would be to use GDScript to move your sprite to the center of the tile you want it to be in.

    You should have some basic knowledge of linear algebra in 2-dimensional Euclidean space. It's not as complicated as it sounds, a 2d vector is just two numbers and almost all linear algebra operations are adding and multiplying the two coordinates of various vectors. There is a short introduction to vectors in the documentation but it has a lot of unnecessary information. You don't need to know the implementation details of collision, the engine handles all that for you.

    Think of coordinates as distances measured off of two perpendicular rulers from a fixed reference point. In Godot and 2d computer graphics in general this is the top-left pixel of the visible area, whether it be the screen, a window, or a viewport. This is shown in the first diagram of the "Vector math" page and if you take away anything from it this should be it.

Sign In or Register to comment.