- Home /
2D Gameplay... planes or cubes?
Hi there,
I was planning on putting together a 2d game, and I was wondering on the best way to go about making platforms. I was originally planning on have everything as a plane, but I'd like to use some physics and it seems that getting planes to collide can be trouble. With that in mind, should I go about making my platforms using meshes with a depth value of 1 (perhaps with the back and bottom faces deleted)... or is there a better method?
Any advise would be greatly appreciated!
Thanks!
Answer by duck · Dec 05, 2009 at 12:24 AM
How about this:
- Create a plane game object
- Remove the collider component from the plane
- Add a box collider component instead
- Make the whole thing into a "platform" prefab
- Use the prefab to build your levels :)
Why not create a plane object, remove the mesh collider, and add a box collider ins$$anonymous$$d? That way you just have one GameObject, rather than 3 (the plane, the box, and the parent)
yes, better idea! I was thinking that you couldn't add a box collider to a plane - but you're right, you can! (although there wasn't a third GO in my suggestion, just two)
I don't recommend using the Unity plane. It contains 200 triangles. You only need 2.
Yes, if the triangle count starts to become an issue, this is something worth considering - however my feeling is that with a significant number of objects, draw calls will become the bottleneck much sooner than tri count, which would force the move to a different method of displaying the level platforms altogether.
Answer by Design3.com · Dec 04, 2009 at 09:53 PM
Unity supplies a 2D Platformer tutorial here. If you use an orthographic camera an align your platforms-as-cubes to it, they'll appear to have no depth. It all depends on the look you're going for, so I'd read the tutorial, which talks about physics a bit, and see how it applies to what you're making.
This is an example of a 2D game without perspective made with Unity.
Here's another.
Hi. Thanks very much for your reply. I have given that tutorial a good read. $$anonymous$$y main query is that I'd prefer to use planes (less faces == more power!) but I don't want to use them at the cost of dodgy physics. Sorry, perhaps my question wasn't very clear.
Answer by Jessy · Dec 04, 2009 at 10:25 PM
The physics system doesn't work with planes, and isn't tied to the rendering. Therefore, you'd probably be best off using textures quads for graphics, and sphere, capsule, and box colliders as appropriate. Make the box as deep as you like!
Small note - the physics system does work with planes - you can collide rigidbodys against them, just not use them as rigidbodys themselves. But they won't behave nicely as platforms if you try and balance objects on them edge-on!
It's an issue of semantics, I suppose, but I say it doesn't work with planes. You have four primitives to work with: sphere, capsule, box, triangle (mesh). You can "make a plane" out of a box or triangles (I suppose one could do if you stretched it out enough), but ultimately, no planes.
Your answer
Follow this Question
Related Questions
Best approach for collision in shape combination game? 0 Answers
Make Player Move Slow Over Grass 1 Answer
Having an array of points(vector2), how do I create a 2d terrain? (new to unity) 2 Answers
Generate collision mesh from 2d texture? 0 Answers
I'd like some help with my health / shooting (collision detection) 1 Answer