# Creating a 3d map (only 2d collisions )

This topic is 1546 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

So I have a simple threejs game with some features but is currently on a 1200x1200 unit square "map" which is just a THREE.PlaneGeometry object. I want to work on a map with a different shape and eventually add impassable terrain + textures to it. It would be 3d but only 2d ( x and z) movement so no height map would be needed. My question is what would be the best way to go about doing this as I have no idea where to start and would like something that I can easily make changes to in the future as things get more complex. As a secondary question, what is the general solution for detecting collision with terrain for large maps? There is collision detection for bullets/characters in my game but am not sure how that translates. I am mainly looking for some direction as I know this may be a complicated topic!

##### Share on other sites

what would be the best way to go

It depends on what your collision detection needs are, as collision detection can be expensive. Can you provide more information with regard to what collision parameters you need? Height-only? Penetration distance for complex shapes (sphere, cylinder, OBB, AABB..)?

For instance, if you only need terrain height for a particular cell (unit square), it is quicker (versus a "collision engine") to do a look-up of y in an array map simply accessed with x-z coordinates. If you need the height within a cell, you can get the height at the four corners and interpolate (either linearly or with a weighted average) if each cell is a flat quad. If the four corners of a quad are used as triangle vertices, you'll need to know whether the triangles form a valley-fold or mountain-fold.

would like something that I can easily make changes to in the future as things get more complex

To "easily" make changes you'll have to decide what "more complex" means, similar to the questions above regarding what collision parameters you'll need. I.e., you can't "easily" go from a map-height look-up scheme (mentioned above) to collision detection for shape-to-shape (sphere-triangle, cylinder-OBB, etc.)

If you have little or no experience with collision detection, can you put into words what you want to do, rather than how you want to do it?

EDIT: With regard to adding textures, that will likely be unrelated to collision detection. In 3D, collision detection is largely a numerical evaluation in which texture coordinates or colors has no part. I.e., more often, collision detection may use the same vertex position data used for rendering, but doesn't need the other graphics related parameters. You can, however, do a lookup of the texture for a cell, if you use a "wall" texture for "impassable," to determine if collision detection is needed. If the cell is "impassable" you can make decisions on response at that point without any further "collision" evaluations. That could also be implemented in the collision engine if you use collision groups defined, perhaps, simply with a bitwise enumeration.

Edited by Buckeye

##### Share on other sites

It depends on what your collision detection needs are, as collision detection can be expensive. Can you provide more information with regard to what collision parameters you need? Height-only? Penetration distance for complex shapes (sphere, cylinder, OBB, AABB..)?

For instance, if you only need terrain height for a particular cell (unit square), it is quicker (versus a "collision engine") to do a look-up of y in an array map simply accessed with x-z coordinates. If you need the height within a cell, you can get the height at the four corners and interpolate (either linearly or with a weighted average) if each cell is a flat quad. If the four corners of a quad are used as triangle vertices, you'll need to know whether the triangles form a valley-fold or mountain-fold.

Only 2d so x and z ( no height). The walls for example would be 3d, but character movement is only 2d ( as in Diablo for example ) so I just want to detect if the character model is colliding with the wall in 2 dimensions and stop it from moving through.

To "easily" make changes you'll have to decide what "more complex" means, similar to the questions above regarding what collision parameters you'll need. I.e., you can't "easily" go from a map-height look-up scheme (mentioned above) to collision detection for shape-to-shape (sphere-triangle, cylinder-OBB, etc.)

If you have little or no experience with collision detection, can you put into words what you want to do, rather than how you want to do it?

EDIT: With regard to adding textures, that will likely be unrelated to collision detection. In 3D, collision detection is largely a numerical evaluation in which texture coordinates or colors has no part. I.e., more often, collision detection may use the same vertex position data used for rendering, but doesn't need the other graphics related parameters. You can, however, do a lookup of the texture for a cell, if you use a "wall" texture for "impassable," to determine if collision detection is needed. If the cell is "impassable" you can make decisions on response at that point without any further "collision" evaluations. That could also be implemented in the collision engine if you use collision groups defined, perhaps, simply with a bitwise enumeration.

I think I answered the first bit above but let me know if it was unclear. The part about  detecting collision with textures is very good info to have as I would need something like that in the future.

Thank you so much for taking the time to respond.

##### Share on other sites

detect if the character model is colliding with the wall in 2 dimensions and stop it from moving through.

Clear enough. If your 3D objects occupy one (or more) full cell(s), a simple array lookup following code for "what x-z cell is the character moving to?" should be quite fast. For collision detection along "lines of flight" (projectiles, spells, etc.) you might look into a simple line-slope calculation, or even 2D raycasting (google for "ray box intersection" or similar) to determine, for instance, which cells projectiles pass through; look up the cell "contents"; and make appropriate responses.

I'm suggesting you keep things as simple as possible for now. It sounds like full-blown collision/physics engines (Bullet, ODE, etc.) at this point would be a drastic overkill.

Edited by Buckeye

##### Share on other sites

Clear enough. If your 3D objects occupy one (or more) full cell(s), a simple array lookup following code for "what x-z cell is the character moving to?" should be quite fast. For collision detection along "lines of flight" (projectiles, spells, etc.) you might look into a simple line-slope calculation, or even 2D raycasting (google for "ray box intersection" or similar) to determine, for instance, which cells projectiles pass through; look up the cell "contents"; and make appropriate responses.

I'm suggesting you keep things as simple as possible for now. It sounds like full-blown collision/physics engines (Bullet, ODE, etc.) at this point would be a drastic overkill.

Thanks you've cleared up the collision detection. Do you have any insight on how I should go about creating the map? I have no idea really how these sort of things are generated. For example, I want to make a map around the size of a typical Moba with walls, perhaps some trees and that sort of thing. I'm just lost on where to start.

http://redshootinghood.info/index.php This is a few years old but I want to make a map similar to that minus the moving up terrain (only 2d movement) as an example!

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633722
• Total Posts
3013549
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!