-
Notifications
You must be signed in to change notification settings - Fork 2
/
examples7 physics.html
42 lines (36 loc) · 1.46 KB
/
examples7 physics.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Physics Testing</title>
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
<script src="//cdn.rawgit.com/donmccurdy/aframe-physics-system/v4.0.1/dist/aframe-physics-system.min.js"></script>
</head>
<body>
<script>
AFRAME.registerComponent('boxgenerator',{
init : function() {
let el = this.el;
el.addEventListener('click', function() {
let scene = document.querySelector("#scene");
let boxBaru = document.createElement("a-box");
let temp = Math.random() * 2- 1;
boxBaru.setAttribute('position',`${temp} 2 -3`);
boxBaru.setAttribute('color','red');
boxBaru.setAttribute('scale','0.2 0.2 0.2');
boxBaru.setAttribute('dynamic-body','shape:box');
scene.appendChild(boxBaru);
});
}
});
</script>
<a-scene id="scene" physics="debug:true">
<a-camera>
<a-cursor></a-cursor>
</a-camera>
<a-plane static-body color="#222" rotation="-90 0 0 " scale="15 15 15"></a-plane>
<a-box boxgenerator color="#F00" position="0 1.5 -2" scale="0.2 0.2 0.2"></a-box>
</a-scene >
</body>
</html>