Matter-js: Question: "static-ish" bodies

Created on 9 Jun 2014  路  3Comments  路  Source: liabru/matter-js

Sorry to open this as an issue: I can't find a forum or discussion area that would be more appropriate. Also, fantastic library - by far my favourite JS physics lib.

I have a side-scrolling platform game, where all the platforms are static bodies. I want to include some swinging platforms that act like static bodies (in that they defy gravity), but also like dynamic bodies in that they can have forces applied to them to make them move.

They should also apply force to other bodies to "bash" them along. My initial version used static bodies and translated them every frame, but then they don't have any velocity - so when they strike a player, the player just slides down the edge instead of pinging off it.

Any ideas would be welcome... and thanks again for the library!

Most helpful comment

Oh, one other trick is to set body.inertia to Infinity so it can't rotate which is good for platforms.

All 3 comments

There's actually a new demo I pushed the other day that may help you a bit with this, it's called "Body Manipulation". You can try it out if you clone the matter-js repo and follow the instructions here to build and run the demo.

It's using some new functions currently only available in the edge build. See the code for the Body Manipulation demo.

My initial version used static bodies and translated them every frame, but then they don't have any velocity - so when they strike a player, the player just slides down the edge instead of pinging off it.

I can see what you mean and I think the above demo may also suffer similar issues even though they're not statics. I think ideally you should be using forces here rather than translation (e.g. Body.applyForce or body.force.x etc) but I imagine that may be difficult to control.

A better way may be able to fiddle around with Matter.constraints to do this - e.g. have them pulling in opposite directions on a body, then dynamically change the constraint points.

Thinking about it more, I imagine motors constraints etc. may need to be implemented to do this properly. So I'll put those on the list of things to look at, but I think the constraints approach is probably your best bet as it is now.

Oh, one other trick is to set body.inertia to Infinity so it can't rotate which is good for platforms.

The Body Manipulation demo is really helpful. I think I can do a bit of hacking (forcing a Y position after every update) combined with the body.inertia = Infinity trick to get what I'm after!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Zhaopengyang picture Zhaopengyang  路  3Comments

cluber22 picture cluber22  路  3Comments

koko236 picture koko236  路  3Comments

car1ot picture car1ot  路  3Comments

kunchenguid picture kunchenguid  路  3Comments