Comments (4)
Hi @thenayr — your code looks OK to me. Here's a similar example of my own, which does work. A common issue is getting the order of scripts right. Generally, you'll need:
<head>
...
<!-- aframe.js -->
<!-- aframe-physics-system.js and any other scripts registering components -->
</head>
<body>
...
<a-scene> ... </a-scene>
<script>
document.querySelector('a-scene').addEventListener('render-target-loaded', function () {
// any code that appends things to the scene
});
</script>
</body>
Code that appends to the scene can also be put inside a component — in that case it should be included before the scene, with other components, as shown here.
from aframe-physics-system.
Thanks.
Looks like the key here was not setting the attribute dynamic-body
prior to appending the element:
# Doesn't work
var box = document.createElement('a-box')
box.setAttribute('dynamic-body', '');
document.getElementById('myscene').appendChild(box)
# Does work
var box = document.createElement('a-box')
document.getElementById('myscene').appendChild(box)
box.setAttribute('dynamic-body', '');
Here is my React implementation (full disclosure, this code is probably gross):
import React from 'react';
import ReactDom from 'react-dom';
import {Entity} from 'aframe-react';
class Pod extends React.Component {
constructor(props) {
super(props);
this.state = {
name: props.name,
color: props.color
}
}
componentDidMount() {
ReactDom.findDOMNode(this).setAttribute('dynamic-body', '');
}
render() {
return(
<Entity
id={`${this.state.name}`}
key={`${this.state.name}`}
geometry={{ primitive: 'box' }}
shape="box"
material={`color: ${this.state.color}; metalness:0.7`} >
<Entity light={{type: 'point', color: '#63C7B2', intensity: '0.2'}} position="0 0 0" />
</Entity>
)
}
}
export default Pod;
from aframe-physics-system.
Possibly related to: supermedium/aframe-react#43
from aframe-physics-system.
Not sure about react (some separate issues opened about that) but AFAIK physics is working ok with new entities now.
from aframe-physics-system.
Related Issues (20)
- Broken in A-Frame 1.2.0 HOT 21
- Getting the impulse force from a collision? (Ammo) HOT 1
- Our version of Cannon calls depreciated THREE.Geometry 14 times HOT 7
- How to prevent 3d model from going out of its physical frame?
- Cannon.js raycast vehicle support
- gltf ammo-shape loading before object3DMap.mesh information in A-frame HOT 1
- Cannon.js repository not found when trying to install aframe-physics-system using npm HOT 2
- gltf model model does not get parsed HOT 9
- Hitting crash in A-Frame Physics System (maybe when switching between kinematic & dynamic?) HOT 4
- Can't change Ammo driver friction coefficient HOT 2
- Cannot install using package managers HOT 7
- AMMO DRIVER Problem with event body-loaded in Chrome HOT 1
- Uncaught ReferenceError: arguments is not defined HOT 4
- Current NPM verison can no longer be installed, but the fix is in master. Please cut a release HOT 4
- Ammo bounce HOT 1
- Hull orientation and position incorrect.
- THREE.Geometry is not a constructor Error Aframe 1.3.0 (>1.0.4) HOT 1
- Add note in README about the c-frame fork HOT 3
- Including the Ammo.js build from mixedreality.mozilla.org HOT 4
- Cannot remove dynamic-body; TypeError: _bi2 is undefined HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aframe-physics-system.