34
\$\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\$
2
  • 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\$ Apr 4, 2014 at 6:07
  • \$\begingroup\$ And now there is also the paid Box2D backend, which should be similar to P2.JS but better. \$\endgroup\$ Jan 23, 2018 at 16:55

1 Answer 1

40
\$\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\$
4
  • \$\begingroup\$ does one incidence of the more precise model decrease performance? \$\endgroup\$ May 18, 2014 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, 2014 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\$ May 21, 2014 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, 2014 at 20:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .