Skip to content

Commit 6bed750

Browse files
authored
Merge pull request #191 from kylebakerio/patch-1
As discussed in #188
2 parents 2dae475 + 2df108e commit 6bed750

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

getting-started.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
There are many ways this library can be used, but many use cases likely can be thought of as a variation off of the ability to pick something up with your controller in 6d0f VR. Here we walk through one possible very quick way to approach adding this ability to your existing application--one suggestion for one scenario. You can riff widely off this concept as needed.
2+
3+
1. Add Libraries:
4+
5+
```html
6+
<script src="https://unpkg.com/super-hands/dist/super-hands.min.js"></script>
7+
<script src="https://cdn.jsdelivr.net/gh/n5ro/[email protected]/dist/aframe-physics-system.js"></script>
8+
<script src="https://unpkg.com/aframe-event-set-component@^4.1.1/dist/aframe-event-set-component.min.js"></script>
9+
<script src="https://unpkg.com/aframe-physics-extras/dist/aframe-physics-extras.min.js"></script>
10+
```
11+
12+
2. Add Physics:
13+
14+
Add the `physics` component to your scene
15+
_note: trying `physics="gravity: 0"` can sometimes help with debugging some issues, try at your own risk._
16+
```html
17+
`<a-scene physics>`
18+
```
19+
20+
3. Add Mixins
21+
22+
Add these mixins within your `<a-assets>`.
23+
```html
24+
<a-mixin id="all-interactions"
25+
hoverable grabbable stretchable draggable
26+
event-set__hoveron="_event: hover-start; material.opacity: 0.7; transparent: true"
27+
event-set__hoveroff="_event: hover-end; material.opacity: 1; transparent: false"
28+
dynamic-body
29+
></a-mixin>
30+
31+
<a-mixin id="grab-move"
32+
hoverable grabbable draggable
33+
event-set__hoveron="_event: hover-start; material.opacity: 0.7; transparent: true"
34+
event-set__hoveroff="_event: hover-end; material.opacity: 1; transparent: false"
35+
dynamic-body
36+
></a-mixin>
37+
38+
<a-mixin id="physics-hands"
39+
physics-collider phase-shift
40+
collision-filter="collisionForces: false"
41+
static-body="shape: sphere; sphereRadius: 0.02"
42+
super-hands="colliderEvent: collisions;
43+
colliderEventProperty: els;
44+
colliderEndEvent: collisions;
45+
colliderEndEventProperty: clearedEls;"
46+
></a-mixin>
47+
```
48+
49+
50+
4. Prevent hands from knocking things away before you grab them
51+
52+
Add the following component to your project:
53+
```js
54+
AFRAME.registerComponent('phase-shift', {
55+
init: function () {
56+
var el = this.el
57+
el.addEventListener('gripdown', function () {
58+
el.setAttribute('collision-filter', {collisionForces: true})
59+
})
60+
el.addEventListener('gripup', function () {
61+
el.setAttribute('collision-filter', {collisionForces: false})
62+
})
63+
}
64+
});
65+
```
66+
67+
5. Give hands the ability to grab
68+
69+
Add the `physics-hands` mixin to your hand entities
70+
```html
71+
<a-entity id="rhand" mixin="physics-hands"
72+
hand-controls="hand: right">
73+
</a-entity>
74+
<a-entity id="lhand" mixin="physics-hands"
75+
hand-controls="hand: left">
76+
</a-entity>
77+
```
78+
79+
6. Make a floor things won't fall through
80+
81+
Add `static-body` component to your ground and whatever surfaces you want to be able to put things on
82+
```html
83+
<a-box static-body width="100" height="0.01" depth="100" visible="false"></a-box>
84+
<!-- if you already have a ground, you should just be able to add static-body to it -->
85+
<!-- Hint: you should also add 'static-body' to any surface you want to be able to set movable things on top of -->
86+
<!-- Hint: if you're adding it dynamically, make sure to use el.setAttribute('static-body', '') -->
87+
```
88+
89+
7. Make your thing able to be picked up
90+
91+
Add the mixin 'all-interactions' (or 'grab-move' if you don't want it to be 'stretchable') to whatever object you want to be able to reach into and pick up.
92+
```html
93+
<a-entity class="cube" mixin="cube all-interactions" position="0 0.265 -1" material="color: red"></a-entity>
94+
```
95+

0 commit comments

Comments
 (0)