Skip to main content
deleted 114 characters in body
Source Link
General Waters
  • 1.6k
  • 2
  • 21
  • 30

In a system where game objects are not conformed to a grid (this is generally called smooth tile base collision), toTo detect collision against any possible tiles/obstacles, you first calculate the object's desired movement and where position on the tile map that movement would cause the object to end up if immediately applied.

You then perform a lookup of the tile map (stored ingenerally via a 2D array representation) of the object's desired position along the x and y axes, and obtain the tile information. If it's a collidable tile, you alter the desired movement appropriately to prevent moving.

To summarize, you essentially look ahead to the position the object wants to move in, and determine if it can move there or not.

This excellent article by Rodrigo Monteiro goes into great depth on how to implement 2d platformers, but can be adjusted for top-down games as well. http://higherorderfun.com/blog/2012/05/20/the-guide-to-implementing-2d-platformers/

In a system where game objects are not conformed to a grid (this is generally called smooth tile base collision), to detect collision against any possible tiles/obstacles, you first calculate the object's desired movement and where position on the tile map that movement would cause the object to end up if immediately applied.

You then perform a lookup of the tile map (stored in a 2D array) of the object's desired position along the x and y axes, and obtain the tile information. If it's a collidable tile, you alter the desired movement appropriately to prevent moving.

To summarize, you essentially look ahead to the position the object wants to move in, and determine if it can move there or not.

This excellent article by Rodrigo Monteiro goes into great depth on how to implement 2d platformers, but can be adjusted for top-down games as well. http://higherorderfun.com/blog/2012/05/20/the-guide-to-implementing-2d-platformers/

To detect collision against any possible tiles/obstacles, you first calculate the object's desired movement and where position on the tile map that movement would cause the object to end up if immediately applied.

You then perform a lookup of the tile map (generally via a 2D array representation) of the object's desired position along the x and y axes, and obtain the tile information. If it's a collidable tile, you alter the desired movement appropriately to prevent moving.

To summarize, you essentially look ahead to the position the object wants to move in, and determine if it can move there or not.

This excellent article by Rodrigo Monteiro goes into great depth on how to implement 2d platformers, but can be adjusted for top-down games as well. http://higherorderfun.com/blog/2012/05/20/the-guide-to-implementing-2d-platformers/

Source Link
General Waters
  • 1.6k
  • 2
  • 21
  • 30

In a system where game objects are not conformed to a grid (this is generally called smooth tile base collision), to detect collision against any possible tiles/obstacles, you first calculate the object's desired movement and where position on the tile map that movement would cause the object to end up if immediately applied.

You then perform a lookup of the tile map (stored in a 2D array) of the object's desired position along the x and y axes, and obtain the tile information. If it's a collidable tile, you alter the desired movement appropriately to prevent moving.

To summarize, you essentially look ahead to the position the object wants to move in, and determine if it can move there or not.

This excellent article by Rodrigo Monteiro goes into great depth on how to implement 2d platformers, but can be adjusted for top-down games as well. http://higherorderfun.com/blog/2012/05/20/the-guide-to-implementing-2d-platformers/