-
Notifications
You must be signed in to change notification settings - Fork 0
/
22-ConstraintSpring.html
57 lines (57 loc) · 2 KB
/
22-ConstraintSpring.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
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simulasi Fisika</title>
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/n5ro/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 newBox = document.createElement("a-box");
newBox.setAttribute("scale", "0.2 0.2 0.2");
newBox.setAttribute("color", "red");
let temp = Math.random() * 2 - 1;
newBox.setAttribute("position", `${temp} 7 -3`);
newBox.setAttribute("dynamic-body", "shape:box");
newBox.setAttribute("spring", "target:#anchor;stiffness:25");
scene.appendChild(newBox);
});
}
});
</script>
<a-scene id="scene" physics="debug:true">
<a-camera position="0 1.5 2">
<a-cursor></a-cursor>
</a-camera>
<a-box
color="red"
id="anchor"
scale="0.5 0.5 0.5"
static-body
position="0 2.5 -3"
wireframe="true"
></a-box>
<!-- <a-box
color="green"
id="moving"
constraint="target:#anchor;type:coneTwist;pivot:0 -0.5 0"
scale="4 0.2 1"
dynamic-body
position="0 3.5 -3"
></a-box> -->
<a-box boxgenerator color="yellow" scale="0.2 0.2 0.2" position="0 1.5 -3"></a-box>
<a-plane
static-body
color="#222"
rotation="-90 0 0"
scale="15 15 15"
></a-plane>
</body>
</html>