Zachernuk

tnSuperman tanktn oParticles uExtrusion j3d sandy flExtrusion fuelyoursenses meshCam bufferSnake dMap2 dMap pv2 cursorFire opticks faceGame FPSnake pv preOpticks painty youtuber fractalFIngers 2dbals

January 30, 2011

Javascript physics!

Filed under: doodles,Games,Uncategorized — Tags: , , , , , — Brandel Zachernuk @ 3:12 pm

A few years ago my friends Bill and Aidan and I started mucking about with the new javascript canvas class, and this is what we came up with. While there are other more robust physics engines out there – even in Javascript – it’s good to know how straightforward it is to get some of that behaviour working. If for any reason you want to use this, please do!

Usage: Click and hold inside the grey square to create a ball. The longer you hold down the mouse, the bigger the ball. Click, drag around, and release a ball to ‘throw’ it. You can change gravity and the drag coefficients by changing the numbers in the boxes below. Gravity can be any number, negative, positive or zero. Drag coefficient is only going to make sense as a number between 0 and 1. Greater than 1 means that energy is added to the system and things get a little crazy!

Note: to see this you will need to be using Firefox, Chrome or Opera.


Click and drag inside this box to make a ball
drag and release to move and throw a ball.

Disclaimer: Given that this was such a casual collaboration, please excuse the messiness of the code. It was just the fastest way to get this kind of thing happening. If you want a more coherent mechanism for control, Box2DJS is the way to go.



(this is just so that a link to this post has a pretty picture to show!)

Older Posts »

Powered by WordPress