x


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!

more ▼

asked Dec 04 '09 at 09:42 PM

Disaster gravatar image

Disaster
482 48 57 67

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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 :)
more ▼

answered Dec 05 '09 at 12:24 AM

duck gravatar image

duck ♦♦
41k 92 148 415

Why not create a plane object, remove the mesh collider, and add a box collider instead? That way you just have one GameObject, rather than 3 (the plane, the box, and the parent)

Dec 05 '09 at 12:47 AM Stelimar

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)

Dec 05 '09 at 12:51 AM duck ♦♦

edited answer to reflect stelimar's suggestion

Dec 05 '09 at 12:54 AM duck ♦♦

I don't recommend using the Unity plane. It contains 200 triangles. You only need 2.

Dec 05 '09 at 07:02 AM Jessy

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.

Dec 05 '09 at 08:37 AM duck ♦♦
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Dec 04 '09 at 09:53 PM

Design3.com gravatar image

Design3.com
640 1 1 10

Hi. Thanks very much for your reply. I have given that tutorial a good read. My 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.

Dec 04 '09 at 10:05 PM Disaster
(comments are locked)
10|3000 characters needed characters left

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!

more ▼

answered Dec 04 '09 at 10:25 PM

Jessy gravatar image

Jessy
15.6k 72 95 196

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!

Dec 05 '09 at 12:27 AM duck ♦♦

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.

Dec 05 '09 at 03:55 AM Jessy
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2495
x1361
x1036

asked: Dec 04 '09 at 09:42 PM

Seen: 7799 times

Last Updated: Dec 19 '11 at 09:39 AM