Matter-js: Force Fields, Infinite Planes and Real circles

Created on 3 Nov 2017  路  3Comments  路  Source: liabru/matter-js

Is there a way to implement force fields.
I visited many physics engines, but neither of them have force fields. If this one has that feature, you are one of the first.
I'm programming a physics engine right now, and that is going to support force fields too.

I have a set of force fields I wanted to use:

  • Point ( Attracts or pushes objects to or from a point [Useful as gravity to point] )
  • Line ( Attracts or pushes objects to or from an (in)finite line )
  • Direction ( Pushes objects in one direction when in area )
  • Anti gravity ( Disables gravity in area )
  • Teleport ( Teleports objects to a point when in area )
  • Vortex ( Rotates objects along point )

I have also a set of force fields that can be applied to bodies:

  • Conveyor ( Pushes objects when they are on the conveyor, or the conveyor rolls when it is dynamic [Just a way of adjusting friction, I think] )
  • Newtonian ( Pulls objects by gravity )

Another thing I see in most physics engines, is an infinite plane shape.
This is an infinite plane:
schermafbeelding 2017-10-19 om 17 28 13 kopie

And at last, I noticed circles are just Regular Polygons with many edges, not just circles ( I just haven't checked this in v0.13.0 ). Your implementation works nicely, but circles are just better:

  • SAT is only using 1 axis on 2 circles. 50-sided RP's use 50 axes. Even for polygon-circle collisions, this is way faster...
  • 50-sided regular polygons can get stuck on surfaces that are rotated a very little bit ( 0.1 degrees ), circles do not.

This is only a feature idea, and I appreciate answers with ways to implement this ideas with the current MatterJS version too.

P.S. An infinite plane is NOT implemented with a big rectangle!

feature-request

Most helpful comment

Is there a way to implement force fields.

Check out matter-attractors which I think actually does some of the things you need. Much of your other ideas can be implemented through custom attractor functions.

Another thing I see in most physics engines, is an infinite plane shape

Would be a pretty nice addition, will try it out.

And at last, I noticed circles are just Regular Polygons with many edges, not just circles ( I just haven't checked this in v0.13.0 ). Your implementation works nicely, but circles are just better

Actually I do have an implementation of this that I really should finish up!

All 3 comments

Is there a way to implement force fields.

Check out matter-attractors which I think actually does some of the things you need. Much of your other ideas can be implemented through custom attractor functions.

Another thing I see in most physics engines, is an infinite plane shape

Would be a pretty nice addition, will try it out.

And at last, I noticed circles are just Regular Polygons with many edges, not just circles ( I just haven't checked this in v0.13.0 ). Your implementation works nicely, but circles are just better

Actually I do have an implementation of this that I really should finish up!

Nice to know that you have an implementation of circles. I looked at matter-attractors, it seems really nice, but does not exactly what I was looking for, except newtonian gravity. But as I saw matter-attractors is a plugin, I think I can write a "matter-forcefields" too. Maybe a thing to try for me.

@liabru I got one question about real circles, can you tell us when we can expect new implementation?
Can you more or less estimate it will be 1 month or 3 months or more?

Was this page helpful?
0 / 5 - 0 ratings