-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEntityEvents.js
More file actions
37 lines (30 loc) · 793 Bytes
/
EntityEvents.js
File metadata and controls
37 lines (30 loc) · 793 Bytes
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
import { Euler, Quaternion, Vector3 } from 'three';
/*
Add custom "entity events" to this file. The EntityFactory
will execute these functions by "key" when the entity
collider event is triggered.
*/
class EntityEvents {
constructor() {
}
static teleport = event => {
event.pair.setPosition(event.value);
}
static bounce = event => {
if (event.pair.rigidBody?.isKinematic()) {
_v.copy(event.pair.velocity);
_v.y = 0.15;
event.pair.velocity.copy(_v);
}
else {
_v.copy(event.pair.rigidBody.linvel());
_v.y = 5; // Bounce upwards
event.pair.rigidBody.setLinvel(_v, true);
}
}
}
// Assign local helper components
const _v = new Vector3();
const _e = new Euler();
const _q = new Quaternion();
export { EntityEvents }