New Physics Benchmark — Pi Testing

After seeing this video… https://www.youtube.com/watch?v=vlUTlbZT4ig …and this video… https://www.youtube.com/watch?v=6dTyOl1fmDo …on YouTube, I wondered if that Physics experiment could be done with Hype.

I got it to work when the elements were the same size and same density. It's three bounces. But changing anything else yielded quite unexpected results.

Here's the template…
pi-test.zip (13.9 KB)

That's when I started wondering about the conversation here… Ideas For Hype 5 Features… - #54 by Photics …is Matter.js the right match for Hype?

I tried to do this manually, with just Matter.js and I got unexpected results. I'm not quite sure where's the problem. Is it with Hype, is it with Matter.js, or are some Physics settings missing?

I tried lots of different things… setVelocity vs applyForce, Density vs Mass, slop, rectangles vs circles, bigger box vs same size box.

Then I'm reminded of the current issue in Hype, where Physics elements either run out of energy (when they shouldn't) or bounce out of the scene (when they shouldn't). I noticed that in this example. If I simply put two walls, and move the lefty block out of the way, the righty block would eventually bounce out of the scene. (That's the Constant Collision Detection issue.)

This hurts Hype because I was psyched… oh cool, I can make a new video about Hype for Pi Day. Unfortunately, it didn't work. :slightly_frowning_face:

Perhaps this information could still be useful. Maybe it's a benchmark of what's good Physics. This shouldn't be complicated. It's a theoretical scenario, with no loss of energy in the system. So, why isn't it working? Where's that extra energy coming from, or where is it going if it's being lost?

Yeah, I was watching those too yesterday, fun videos :slight_smile:

It might be good to elaborate on exactly what you see.

If I increase the density of the right object to 100, I get a result more similar to the video. There is extra energy imparted though.

I can see this setup was 19 collisions. However I think the general problem is that the velocity is too high and timing step precision or framerate is too low, so this is probably yielding some of the general collision bugs we've seen before. Beyond the going through walls issue, it often "ejects" stuff at high velocities. I don't know the code exactly, but perhaps if there's an overlap in bodies it places the body outside the overlapping area, which imparts extra velocity? I'm not too sure.

So if I change the initial velocity to a value of -3, then there's smaller body steps.

In fact, doing this with a density of 1:100 yields 30 collisions! (verified by doing a PNG sequence export at 60fps for 11s)

Pretty close :sunglasses:!!!

If lost, I'd guess some is going into this bug:

Either way, there might also be a couple spots where Hype is leading to less precision as well. You could try a more pure version in just matter.js, but I suspect it will be about the same result.

Nonetheless, a fun experiment :slight_smile:.

Now for absolute fun I increased the density to 10,000 and set the initial x velocity to -1.

It kinda sticks to the object and looks like it goes haywire. However, on a PNG sequence export you can count the frames and see where it is going back and forth.

For me, it went "haywire" bouncing back and forth between frames 739 and 1062. Which is...

324 total collisions! Pretty close!

Oh, I'm familiar with that one. :smile:
A couple of posts over there are mine. :slightly_smiling_face:

I suppose I didn't expect this to work, at least not with higher numbers. How could it work if the collisions occur faster than the frames per second. It often goes back to those two main issues… unexpected energy loss/gain and no CCD.

I think it's more about an overall issue I've been having with Hype and Physics. There's something I imagine, so I try creating it in Hype, but then it doesn't work as expected. There's either a strange glitch or the Physics isn't as responsive as expected.

Your first video was closer to what was envisioned, but not quite right. The second video… it's certainly not close visually.

I did try using just Matter.js. That's the “I tried to do this manually” part.

What was nice was that there were more options. Hype doesn't have settings for slop, mass, infinity inertia, and other nice features of the Physics API. It can be done manually, but that can be a challenge for people using Hype.