forked from n5ro/aframe-physics-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cannon.html
48 lines (46 loc) · 2.42 KB
/
cannon.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
43
44
45
46
47
48
<!DOCTYPE html>
<html>
<head>
<title>Examples • CannonDriver</title>
<meta name="description" content="Hello, WebVR! - A-Frame">
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
<script src="../dist/aframe-physics-system.js"></script>
<script>
AFRAME.registerComponent('bounce', {
init: function() {
this.direction = 1;
this.position = new THREE.Vector3();
this.position.copy(this.el.object3D.position);
setTimeout(() => {
this.ready = true;
}, 3000);
},
tick: function() {
if (!this.ready) return;
var position = this.el.object3D.position.y;
if (position <= 0) {
this.direction = 1;
} else if (position >= 5) {
this.direction = -1;
}
this.el.object3D.position.set(this.position.x, position + 0.05 * this.direction, this.position.z);
}
});
</script>
</head>
<body>
<a-scene physics="debug: false; gravity: -9.8;">
<a-camera near=0.001></a-camera>
<a-box position="-1 5 -5" rotation="0 45 0" color="#4CC3D9" shadow body="shape: box;"></a-box>
<a-box id="target" position="1 3.75 -4" rotation="0 45 0" color="purple" shadow body="shape: box;"></a-box>
<a-sphere position="0 10 -10" radius="1.25" color="#EF2D5E" shadow body="shape: sphere;"></a-sphere>
<a-cone position="0 3.75 -4" radius-bottom="1.25" color="green" shadow bounce body="type: static; shape: cone; addCollideEventListener: true; collisionFlags: 4" constraint="target: #target;"></a-cone>
<a-torus position="-1 3.75 -7" radius="1.25" scale="0.5 0.5 0.5" color="red" shadow body="shape: capsule; cylinderAxis: z;"></a-torus>
<a-torus-knot position="0 3.75 -5" radius="1.25" scale="0.5 0.5 0.5" color="blue" shadow body="addCollideEventListener: false;"></a-torus-knot>
<a-cylinder segments-height="1" segments-radial="10" position="1 4.0 -5" radius="0.5" height="1.5" color="#FFC65D" shadow body="shape: cylinder"></a-cylinder>
<a-plane position="0 2 -4" rotation="90 0 0" width="1" height="1" color="#7BC8A4" shadow body="type: static; mass: 0; shape: box;"></a-plane>
<a-torus-knot position="0 0 -7" radius="1.25" scale="5 0.1 5" rotation="0 90 0" color="#7BC8A4" shadow body="type: static; mass: 0; shape: box;"></a-torus-knot>
<a-sky color="#ECECEC"></a-sky>
</a-scene>
</body>
</html>