34

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.

Philip Allgaier
  • 2,863
  • 4
  • 25
  • 35
Vijay
  • 443
  • 1
  • 4
  • 4
  • 1
    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. – congusbongus Apr 04 '14 at 06:07
  • And now there is also the paid Box2D backend, which should be similar to P2.JS but better. – Ciro Santilli OurBigBook.com Jan 23 '18 at 16:55

1 Answers1

40

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).

ashes999
  • 11,261
  • 9
  • 59
  • 95
  • does one incidence of the more precise model decrease performance? – expiredninja May 18 '14 at 08:55
  • @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. – ashes999 May 18 '14 at 09:38
  • i guess I was wondering about what the thresholds generally are in terms of number and/or complexity of objects. – expiredninja May 21 '14 at 19:09
  • 2
    @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. – ashes999 May 21 '14 at 20:35