Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What are the benefits of a wall being as a plane or as a box? Should I use a plane with a box collider instead of mesh collider?

share|improve this question
up vote 12 down vote accepted

There's going to be a couple different things that you'll need to consider.

Note: that the benefits from the optimizations described below only really matter with a ton of walls. At that point, it might be wise to consider a different solution like binary space partitioning (BSP) for making your walls in your game. This would make your levels highly optimized for rendering (if designed correctly) and for physics (as you have a very good definition of what collides and what doesn't.

Rendering

A box is going to take more to render than a plane. It has more vertices and triangles meaning your vertex shader and the rasterizer are going to have to be run over more data. Therefore, only use a box when you need to in terms of visibility. Remove faces as needed for what the player will need to see.

Physics

You should always use a BoxCollider as opposed to a MeshCollider when you can. MeshColliders have to apply collisions per face (or as a convex hull) of the mesh and make raycasting and physics slower (but it's a negligible amount for just one box). Another thing with BoxColliders is that it's much harder for the player to phase through them when they are going really fast. Even with continuous collisions, if you find yourself still having things phase through walls, you can always just expand the BoxColliders

Productivity

If you're much faster working with planes with MeshColliders (because you don't need to adjust all the BoxColliders to match their dimensions) it may be fine to just use those if you get the performance you desire.

share|improve this answer

Expanding a bit on "Coburn"'s points:

Rendering: If you render the wall as only a plane, then the wall will only be visible from one side, as the plane (or more exactly its faces) only has one rendered side. So if the player is able to move around the wall, you would need multiple planes to cover all the sides, which means you end up with a box anyway.

Physics: Simple geometry colliders (spheres, boxes, etc.) are always faster to compute compared to full mesh colliders since not all faces of the mesh have to be checked individually. Instead "simple" raycasts can be used or distance calculations (e. g. distance to center of sphere minus sphere size).

For other physics engines that have a separate "plane collider" (which Unity doesn't), there is no "better" one. A plane might be slightly faster performance-wise, but you might then run into the issue of fast objects passing through it without actually colliding. Then you are left with either having thicker colliders (so box instead of plane) or move to Continous Collission Detection (CCD), as explained here.

share|improve this answer
    
You can almost always turn backface culling off. – Bálint 19 hours ago
2  
@Bálint True. The user might then see the wall also from the other side although with wrong lighting in that case (light sent by the sources from the other side/room, instead the one he/she is standing in). – Philip Allgaier 19 hours ago
    
In your second point you didn't actually specify whether it is a pro or a con and for what. A plane seems simpler geometrically than a box, so is that your point? – Bakuriu 14 hours ago
    
@Bakuriu As far as I know, Unity does not have a "plane collider", so "box" is the nearest thing. I added a note for other physics engines. – Philip Allgaier 10 hours ago

One more thing about Rendering: When you have your own shadow-mapping implementation, walls made out of boxes can be superior to walls made out of planes due to peter-panning that can appear with planes.

Here's an explanation of the symptom:

http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/#peter-panning

share|improve this answer
    
What is peter-panning? – Pichi Wuana 21 hours ago
    
did you follow the link that i provided? should be self-explanatory. – Djindjidj 20 hours ago
    
ooooh ok thanks! – Pichi Wuana 20 hours ago

I was always told that if u are going to have shadows that its best to make it solid to help with light bleeding because the difference in depth is to small and it will bleed.

I could be wrong, but I make all of my walls and stuff like that two sided, a wall will only be a few verts so it shouldn't be that much of a saving by having it a plane.

There are some things that I leave sides of but its mostly the bottom or top of stuff that has lots of stuff around it to help with light bleeding.

I do the same for physics, didn't every really think about it but to me it seemed right to use a wall as a wall and a plane as a plane but that is just me

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.