Giter Club home page Giter Club logo

aframe-physics-components's Introduction

aframe-physics-components

Also check out Don McCurdy's physics implementation in aframe-extras.

Experimental physics components for A-Frame VR using cannon.js.

physics2

Usage

Browser Installation

Install and use by directly including the browser files:

<head>
  <title>My A-Frame Scene</title>
  <script src="https://aframe.io/releases/0.2.0/aframe.min.js"></script>
  <script src="https://github.com/ngokevin/aframe-physics-components/blob/master/dist/aframe-physics-components.min.js"></script>
</head>

<body>
  <a-scene physics-world="gravity: 0 -9.8 0">
    <a-entity physics-body="boundingBox: 1 1 1; mass: 5; velocity: 0.2 0 0"
              geometry="primitive: box" material="color: red"></a-entity>
  </a-scene>
</body>

NPM Installation

Install via NPM:

npm install aframe-physics-components

Then register and use.

require('aframe');
require('aframe-physics-components');

API

physics-body Component

Property Description Type Default Value
angularVelocity (in deg/s) vec3 0 0 0
boundingBox Collision box (in m). vec3 0 0 0
mass (in kg) number 1
velocity (in m/s) vec3 0 0 0
Event Name Description
collide Emitted when entity collides with another entity. Event contains contact.
applyImpulse (impulseVec3, positionVec3)

Applies an impulse (indicated by impulseVec3) at the body's local point (indicated by positionVec3). forceVec3 is in Force / Time (Newtons / Seconds).

// Applies a small force from left-to-right to the top-left of the body.
var hitMeBody = document.querySelector('#hit-me-entity').components['physics-body'];
hitMeBody.applyImpulse({ x: 10, y: 0, z: 0 }, { x: -1, y: 1, z: 0 });

physics-world Component

Property Description Default Value
gravity vec3 0 -9.8 0
Event Name Description
beginContact Emitted when an entity in the world begins contact with another entity. Event contains bodyA and bodyB.
endContact Emitted when an entity in the world ends contact with another entity. Event contains bodyA and bodyB.

aframe-physics-components's People

Contributors

cvan avatar daoshengmu avatar donmccurdy avatar jhsu avatar mattdesl avatar ngokevin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.