Repository navigation
Expand file tree
/
Copy pathSlidingDoor.re.ts
More file actions
87 lines (77 loc) · 2.44 KB
/
Copy pathSlidingDoor.re.ts
File metadata and controls
87 lines (77 loc) · 2.44 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import * as RE from 'rogue-engine';
import * as THREE from 'three';
import RapierBody from '@RE/RogueEngine/rogue-rapier/Components/RapierBody.re'
export default class SlidingDoor extends RE.Component {
@RE.props.num() slideTo_X = 0;
@RE.props.num() slideTo_Y = 0;
@RE.props.num() slideTo_Z = 0;
@RE.props.num() timeToOpen = 1;
doorClosed = true;
startingPos : THREE.Vector3;
moveDoor = false;
move: THREE.Vector3;
endPos: THREE.Vector3;
thisObject: THREE.Object3D;
moveCount = 0;
awake() {
this.thisObject = this.object3d;
this.startingPos = this.object3d.position;
let t = this.timeToOpen*30;
this.move = new THREE.Vector3((this.slideTo_X/t),(this.slideTo_Y/t),(this.slideTo_Z/t));
this.endPos = new THREE.Vector3(this.slideTo_X, this.slideTo_Y, this.slideTo_Z);
}
update() {
if(this.object3d.userData.actuateDoor == true){
if(this.moveCount == 0){
this.moveDoor = true;
}
this.object3d.userData.actuateDoor = false;
}
if(this.moveDoor){
if(this.doorClosed){
moveDoorAdd(this.move, this);
this.moveCount += 1;
if (this.moveCount == this.timeToOpen*30){
this.doorClosed = false;
this.object3d.userData.doorOpen = true;
this.moveDoor = false;
this.moveCount = 0;
}
}else{
moveDoorSub(this.move, this);
this.moveCount += 1;
if (this.moveCount == this.timeToOpen*30){
this.doorClosed = true;
this.object3d.userData.doorOpen = false;
this.moveDoor = false;
this.moveCount = 0;
}
}
}
function moveDoorAdd(mv: THREE.Vector3, comp:RE.Component){
const rigidbody = RE.getComponent(RapierBody, comp.object3d);
if(rigidbody){
let newPos = rigidbody.body.translation();
newPos.x += mv.x;
newPos.y += mv.y;
newPos.z += mv.z;
rigidbody.body.setNextKinematicTranslation(newPos);
}else{
comp.object3d.position.add(mv);
}
}
function moveDoorSub(mv: THREE.Vector3, comp:RE.Component){
const rigidbody = RE.getComponent(RapierBody, comp.object3d);
if(rigidbody){
let newPos = rigidbody.body.translation();
newPos.x -= mv.x;
newPos.y -= mv.y;
newPos.z -= mv.z;
rigidbody.body.setNextKinematicTranslation(newPos);
}else{
comp.object3d.position.add(mv);
}
}
}
}
RE.registerComponent(SlidingDoor);