All Projects → liabru → Matter Attractors

liabru / Matter Attractors

Licence: mit
an attractors plugin for matter.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Matter Attractors

A File Icon Idea
Atom File Icons plugin for IntelliJ IDEA products
Stars: ✭ 90 (-3.23%)
Mutual labels:  plugin
Pyautolens
PyAutoLens: Open Source Strong Gravitational Lensing
Stars: ✭ 90 (-3.23%)
Mutual labels:  physics
Farnet
Far Manager framework for .NET, PowerShell, F#.
Stars: ✭ 92 (-1.08%)
Mutual labels:  plugin
Sketch Dockpreview
A Sketch plugin that lets you preview your current artboard in the Dock.
Stars: ✭ 90 (-3.23%)
Mutual labels:  plugin
Fzf.kak
FZF for Kakoune
Stars: ✭ 90 (-3.23%)
Mutual labels:  plugin
Autovalueplugin
AutoValue plugin for IntelliJ
Stars: ✭ 91 (-2.15%)
Mutual labels:  plugin
Constantine
A plugin for Clang compiler
Stars: ✭ 89 (-4.3%)
Mutual labels:  plugin
Sniprun
A neovim plugin to run lines/blocs of code (independently of the rest of the file), supporting multiples languages
Stars: ✭ 93 (+0%)
Mutual labels:  plugin
Vue Raven
vue-raven automatically reports uncaught JavaScript exceptions triggered from vue component
Stars: ✭ 91 (-2.15%)
Mutual labels:  plugin
Psrealvehicle
Plugin for Unreal Engine 4 with simple force-driven vehicle simulation
Stars: ✭ 92 (-1.08%)
Mutual labels:  physics
Z1 Aggressorscripts
适用于Cobalt Strike的插件
Stars: ✭ 91 (-2.15%)
Mutual labels:  plugin
Filebrowser
📂 Web File Browser
Stars: ✭ 13,854 (+14796.77%)
Mutual labels:  plugin
Wordpress Qcloud Cos
💾 使用腾讯云对象存储服务COS作为附件存储空间的WordPress插件。QQ交流群:887595381
Stars: ✭ 91 (-2.15%)
Mutual labels:  plugin
Wordpress Seo
Yoast SEO for WordPress
Stars: ✭ 1,301 (+1298.92%)
Mutual labels:  plugin
Swipe
A plugin for Unreal Engine 4 that exposes swipes on mobile devices as events in blueprint.
Stars: ✭ 91 (-2.15%)
Mutual labels:  plugin
Teepay
Typecho 个人支付宝、微信收款插件
Stars: ✭ 90 (-3.23%)
Mutual labels:  plugin
Vim Gfm Syntax
GitHub Flavored Markdown syntax highlight extension for Vim
Stars: ✭ 91 (-2.15%)
Mutual labels:  plugin
Cypress Webpack Preprocessor
Cypress preprocessor for bundling JavaScript via webpack
Stars: ✭ 93 (+0%)
Mutual labels:  plugin
Computer Science Resources
A list of resources in different fields of Computer Science (multiple languages)
Stars: ✭ 1,316 (+1315.05%)
Mutual labels:  physics
Homebridge Cmd4
CMD4 Plugin for Homebridge - Supports ~All Accessory Types & now all Characteristics too
Stars: ✭ 92 (-1.08%)
Mutual labels:  plugin

matter-attractors

An attractors plugin for matter.js

Build Status

This plugin makes it easy to apply continual forces on bodies. It's possible to simulate effects such as wind, gravity and magnetism.

Demo

See the demo.

matter-attractors

Install

Get the matter-attractors.js file directly or get it via npm:

npm install matter-attractors

Dependencies

Usage

Matter.use('matter-attractors');
// or
Matter.use(MatterAttractors);

See Using Plugins for more information.

Custom attractors

Attractors are just functions that are pushed to body.plugin.attractors. An attractor function accepts two bodies bodyA and bodyB, where bodyA is always the attracting body and bodyB is the body being attracted.

The attractor will be called against every other body in the engine in the place of bodyB, on every engine update. If a force is returned, it will be applied to bodyB only.

Basic usage

An example of a body that attracts other bodies to it:

var body = Matter.Bodies.circle(0, 0, 10, {
  plugin: {
    attractors: [
      function(bodyA, bodyB) {
        return {
          x: (bodyA.position.x - bodyB.position.x) * 1e-6,
          y: (bodyA.position.y - bodyB.position.y) * 1e-6,
        };
      }
    ]
  }
);

It's possible here to use collision filters too if needed, by using Detector.canCollide and returning null to skip the pair.

Advance usage

In advance usage, e.g. where forces apply to both bodies, instead of returning the force it can instead be applied manually to both bodies inside the function using Body.applyForce.

var body = Matter.Bodies.circle(0, 0, 10, {
  plugin: {
    attractors: [
      function(bodyA, bodyB) {
        var force = {
          x: (bodyA.position.x - bodyB.position.x) * 1e-6,
          y: (bodyA.position.y - bodyB.position.y) * 1e-6,
        };

        // apply force to both bodies
        Body.applyForce(bodyA, bodyA.position, Matter.Vector.neg(force));
        Body.applyForce(bodyB, bodyB.position, force);
      }
    ]
  }
);

Built in attractors

There are some attractors you can push to body.plugin.attractors:

  • MatterAttractors.Attractors.gravity - uses Newton's gravitational laws to apply an attractive force on both bodies

Documentation

See the API docs.

Examples

Check out the examples or try them out first:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].