Is there a Physics API? šŸ¤”

Another good idea for a Physics API is collision detection by type.

Exampleā€¦ if you have a tank and a helicopter, the helicopter should fly over the tank ā€“ but the projectiles from the tank should hit the helicopter.

Iā€™m not sure, but I think the terminology for this in Matter.js is collision filtering. The following thread seems relatedā€¦ https://github.com/liabru/matter-js/issues/48

1 Like

Over the weekend, I got Pac Man Championship Edition DX for iOS. Wow, time flies. I was playing it on the PS3 almost five years agoā€¦ https://photics.com/pac-man-championship-edition-dx-review/

Anyway, as Iā€™m playing this game, Iā€™m thinking in my head about Hype. If there was a physics API, could this game be made with Hype? The one feature that really stood out was the ā€œbullet-timeā€. Whenever Pac Man is about to collide with a ghost, the game slows down. Itā€™s a lot of fun. Iā€™m thinking Matter.js could do this, as it has something called ā€œTime Scalingā€.

Wow, that would be interesting with Hype. Of course, thatā€™s probably not easy to implement, as how would that work with the timeline? Yet, it if did, a whole project could be sped up or slowed down with a global ā€œTime Scalingā€ setting.

2 Likes

I recently saw mention of Hype 3.5 by @stephen in another thread. So, maybe this thread will see some action again. Is Hype working on better Physics settings?!

Also, while not quite Physics related, I think Full-Screen view should be a default option in Hype ā€“ a way to toggle between regular and full-screen modes. If Hype is going to have video game like features, full-screen is a great way to show that off.

The new Apple TV is supposedly comingā€¦

ā€¦and supposedly an SDK for third-party developers is on the way. If thatā€™s true, one of the first things Iā€™d probably look for is if ā€œWKWebKitā€ is available. Iā€™d be able to create a game once, but port it to so many different platforms.

It looks like things are about to get interesting.

Ha, that is an interesting way to do top/left movement with timelines! You'd probably want the general collision detection to be in javascript based on tiles and just allow changing direction based on that.

Sorry, the new forums are harder to track than our old ones and if I'm off the radar for a little bit I can lose posts to see or respond to!

We used to all be in SF together, but earlier this year Daniel's fiancee got a job in NYC and so he moved out there. It is nice having everyone in one office, but we have tools that help us collaborate and so it has gone pretty smooth.

Time scaling is indeed a cool feature; it'd be easy to implement (simply change the wall clock time by a multiple), but the Hype app interface would be confusing (since there'd need to be top-level keyframes for the "time" on the animation timeline!). Also for keyframe animations there's less of a need since animators have it within their control to do whatever they want.

Don't hold your breath for much difference in Physics in 3.5, sorry! The release is more focused on making lots of small improvements and Physics is a bigger item than we wanted to tackle in this specific version.

1 Like

Well, @Daniel, as Taylor Swift says... Welcome To New York.

2 Likes

Iā€™m working on the ā€œInspector: Physicsā€ section in ā€œA Book About Hypeā€, and Iā€™m noticing a few thingsā€¦

  1. Gravity (both force and angle) should be timeline properties
  2. Density, Bounce, Friction and Air Drag can be set to negative. Iā€™m thinking it probably shouldnā€™t be able to do that. Itā€™s not logical and the results are weird.
  3. Density, Bounce, Friction and Air Drag donā€™t seem to affect elements with a ā€œStaticā€ ā€œBody Typeā€. What if I wanted to make a trampoline or an icy walkway? I suppose there are other ways to do that. This is more of clarification. Is that intentional? If so, perhaps these four settings should be grayed out unless ā€œDynamicā€ is selected.
  4. There should be another setting for rotation ā€“ Allow Rotation / No Rotation. Sometimes I just want a ball to bounce up and down. With rotation, the results can be erratic.

I noticed that @jonathan mentioned this thread in another thread by @Franeko. The question was actually related to real world physics, like the accelerometer.

Itā€™s actually really easy to get accelerometer data and use it in a Hype projectā€¦

event.accelerationIncludingGravity.x

Maybe that should be part of the Hype Physics API too, but it seems too simple. This thread has been about accessing Matter.js. Iā€™ve had success working with Accelerometer data in my Hype projects. Matter.js in Hype is different. Thereā€™s so much potential there, but I canā€™t access it.

2 Likes

It looks like the Apple TV (tvOS) is on the way. Iā€™m not sure, but itā€™s looking like tvOS will support web views.

https://developer.apple.com/library/prerelease/tvos/documentation/UIKit/Reference/UIWebView_Class/index.html#//apple_ref/c/tdef/UIWebViewNavigationType

2 Likes

Heh, nope.

If this is the case that wellā€¦very disappointed. Maybe they will open it up after it has been out for awhile.ā€¦I hope

What's odd is that I thought I saw something about a web browser being shown on the Apple Watch. I'm not entirely sure, as I don't have an apple watch, but I think it might support webviews. Why Apple would allow that for a watch, and not a TV, is strange.

The argument I've been hearing is that Apple wants high-quality apps for the Apple TV. Naturally, I disagree.


Anyway, I saw something interesting. I'm not sure if it was discussed...

http://brm.io/matter-js-docs/classes/Vertices.html#method_fromPath

I'm imagining a future ā€“ one where Hype supports vector drawing and that shape is used as a custom collision shape.

1 Like

As a detail: we do use the fromPath API already for the round rectangles and ellipse shapes. The version currently included in Hype didn't have support for concave polygons so that limited a lot of what we could do, but it has since been implemented so the door for shapes is quite open in the future :smile:.

2 Likes

Matter.js is impressiveā€¦ http://brm.io/matter-js-demo-master/#svg ā€¦but that version seems to be in development.

A lot of projects become possible with Hype if SVG and custom (convex) collision shapes are available ā€“ especially if an image can be embedded into the SVG.

Update: I noticed something interesting in the SVG example. By clicking the ā€œshowInternalEdgesā€ option, it shows that the collision shapes arenā€™t really convex. Instead, itā€™s just a series of concave shapes grouped together.

It looks like the shape edges are comprised of straight lines and not BĆ©zier Curves. If the SVG isnā€™t flattened out too, thatā€™s not a huge issue. The collision shape is invisible. I think this is what happens now with chamfering.

The rounded edges in Hype look round. But in the Matter.js example, they look like lots of straight edges.

I noticed something different today. The keyCode numbers are different from Hype's "On Key Press" event than manually using the following JavaScript...

window.onkeydown=function(event){

I was working on getting Fullscreen mode to work, which is ideal for gaming, when I noticed the "F" keyCode was "70" when I used "onkeydown", but "102" when using Hype's "On Key Press" scene event.

It took me a while to realize what's going on. "On Key Press" appears to be case sensitive. It doesn't register the shift key right away. So if you've been following along in this thread, wondering why the keyCode numbers don't work, it might be the difference between onkeydown and onkeypress.

1 Like

We feed a lot of small straight edges to matter.js; they take a "path" that is a series of points. We do the math to figure out a close approximation of roundness.

Note that this isn't related to Hype; it is just a difference between the keydown and keypress event. Hype does expose both, since they are (unfortunately) quite different. I'd recommend reading the post mentioned in here:

I think I might have landed on that page when trying to figure out what was going on. :blush:

I must have been really tired last weekend. I looked again and I can see that both are available. That's cool, because the difference is important for game development. An example would be pinball ā€“ where shift keys are great for flipper control.

Note to self... use event.location for detecting the difference between the shift keys.

This may be unrelated to the current thread but since finding out this thread Iā€™ve been trying to analyse matterjs since itā€™s extremely fast on ipad but itā€™s documentation is really bare bone compared to something like physicsjs. Do you have any source of documentation apart from the docs page there you could share? Like any experiments youā€™ve found or experiments youā€™ve created using that library? Iā€™d be very much interested in either of those to see it in use by others!

2 Likes

I mainly read the source code. At the time the documentation was good (at describing the APIs, not necessarily as tutorial material), but there were a few parts out of date.

Now that A Book About Hype is out, I can post about something that Iā€™ve been waiting weeks to show off.

While Hype still needs improvement with a Physics API, two new JavaScript APIs create lots of potential with game development. The ā€œBounceā€ project would have been a lot more difficult, if at all possible, before Hype 3.5. Good stuff is on the way! :smiley:

1 Like

Hey @jonathan and @Daniel,

Why isnā€™t gravity a timeline property? Is there a way to change it while the project is running?