Physix - A simple physics toy

Earlier today I was being asked about physics for a game someone is planning to work on, so I decided to write a demo showing how physics can be done.


Features crept in and now it’s a quaint little physics toy.

No object-object collisions, but it’s got gravity, restitution, friction, points, vectors and other magic:

Github Repo

Releases (with .hex files)

Not bad for 2-3 hours of semi-idle work.

For those who own a Pokitto, I just ported it to Pokitto.


Nice little example - you might want to tell people how to turn gravity on and off.

If this is for a mutual Canadian friend, I think you might have over-complicated it a touch. :slight_smile:

There’s a function called updateInput with a comment saying // Down - toggle gravity on/off within an if(arduboy.pressed(B_BUTTON)) condition.

What more do people want? :P

Yes and no.

The framework is probably a bit complicated to begin with, but truthfully I think this is a good starting place for teaching about classes. Point2 and Vector2 are very simple in what they do and they’re an excellent way of introducting operator overloading.

And the use of FixedPoints is a simplication over manually handling the fixed points. Also most of the interactions are simple when taken out of context, like applying gravity.

The most difficult case is the wall boundaries.
About 30% of the time was spent fiddling with that.

Anyway, this was more for demonstration and education purposes (and got a little out of hand).

I went through the code but others may not. It might also pay to put up a ProjectABE link.

Don’t get me wrong, it’s great!

1 Like

Nice! Fun to toy around with.

1 Like

Yeah *screams in fangirl*
I’ve also had thoughts about this and it’s great to see it from you.

For the certain someone - and of course for everybody interested - I really can recommend the book The Nature of Code. And the best thing about it: it’s available for free to read online.

It’s in my opinion the most understandable and intuitive book for teaching coding with physics. It explains the math from the very start by explaining vectors, goes over classical mechanics and autonomous agents up to neural networks. That sounds really heavy but it is explained super simple and in a totally understandable way.

1 Like

I just had a quick look at the book and it looks incredibly well written. Great link @Botisaurus… You can find a rendered HTML version here >


After writing the physics toy, I noticed your ‘PointMath.h’.
I couldn’t help but think “you could have used this Vector2 class”.

(Personally I think the Point struct that comes with Arduboy2 is far too simple to be useful. It doesn’t even have any constructors.)

I’ll make a note to read that.
If I like it I might add it to my resource collection:

Personally for maths stuff, my favourite resource is a Youtube series called “Math for Game Developers” by Jorge Rodriguez.
(It’s extremely rare for me to recommend a Youtube series.)

I like it because it gives use cases for the different things it teaches, like using the dot product of two vectors to detect a backstab in a TF2-like game.

1 Like

I’m going to do that :slight_smile:

Yes agreed. A good vector class and basic understanding of linear algebra helps a lot in gamedev.

Sounds interesting, gonna take a look at it.

1 Like