33
\$\begingroup\$

I am a beginner and trying to learn game development using Phaser. Currently Phaser is providing three physics systems namely Arcade, P2 and Ninja. But I don't know the differences between them and I would also like to know in which scenario we should use a particular physics system?

Please give me some insight for these physics systems.

\$\endgroup\$
  • 1
    \$\begingroup\$ Phaser ships with our Arcade Physics system, Ninja Physics and P2.JS - a full body physics system. Arcade Physics is for high-speed AABB collision only. Ninja Physics allows for complex tiles and slopes, perfect for level scenery, and P2.JS is a full-body physics system, with constraints, springs, polygon support and more. \$\endgroup\$ – congusbongus Apr 4 '14 at 6:07
  • \$\begingroup\$ And now there is also the paid Box2D backend, which should be similar to P2.JS but better. \$\endgroup\$ – Ciro Santilli 新疆改造中心法轮功六四事件 Jan 23 '18 at 16:55
39
\$\begingroup\$

As mentioned in the comments, their site already explains what the three systems are and what they can be used for.

Arcade Physics is for high-speed AABB collision only.

AABB means axis-aligned bounded rectangles; it means you have objects without rotation, and you're only checking if the image (which is a rectangle) overlaps with another image (so there's a potential collision). This is cheap to compute, and fast, which is probably why they recommend it for high-speed collisions.

One issue with AABB is that it doesn't guarantee that there really is a collision; you may have a completely transparent area overlapping.

Ninja Physics allows for complex tiles and slopes, perfect for level scenery, [...]

Remember how AABB is non-rotated? Ninja Physics will handle rotations (so it can do slopes and complex tiles). This is a more flexible (and probably more accurate) physics model; it's probably slower.

[...] P2.JS is a full-body physics system, with constraints, springs, polygon support and more.

If you need to model springs (eg. something swinging like a pendulum), constraints on forces, and arbitrary polygon shapes (eg. tetrahedron), this sounds like what you want. If you want a frame of reference, think of something like Angry Birds.

Based on your game, you can pick which is the best-fit to your needs. It sounds like a spectrum of speed versus accuracy/complexity (Arcade Physics being the fastest but simplest).

\$\endgroup\$
  • \$\begingroup\$ does one incidence of the more precise model decrease performance? \$\endgroup\$ – expiredninja May 18 '14 at 8:55
  • \$\begingroup\$ @expiredninja yes, of course. AABB is fast and cheap; the other two are more complex and feature-rich (eg. slopes, rotations) so they come at a performance cost. \$\endgroup\$ – ashes999 May 18 '14 at 9:38
  • \$\begingroup\$ i guess I was wondering about what the thresholds generally are in terms of number and/or complexity of objects. \$\endgroup\$ – expiredninja May 21 '14 at 19:09
  • 2
    \$\begingroup\$ @expiredninja that will depend largely on your hardware and game logic. I suggest you open another question, or better yet, just try them and see what works best for your needs. \$\endgroup\$ – ashes999 May 21 '14 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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