-
Notifications
You must be signed in to change notification settings - Fork 1
/
elevator_controller.cpp
37 lines (31 loc) · 1.28 KB
/
elevator_controller.cpp
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
#include "elevator_controller.h"
using namespace godot;
void ElevatorController::_register_methods() {
register_method("_ready", &ElevatorController::_ready);
register_method("_physics_process", &ElevatorController::_physics_process);
register_property("speed", &ElevatorController::speed, 0.0f);
register_property("height", &ElevatorController::height, 0.0f);
}
ElevatorController::ElevatorController() {}
ElevatorController::~ElevatorController() {}
void ElevatorController::_init() {}
void ElevatorController::_ready() {
init_translation = get_translation();
}
void ElevatorController::_physics_process(float delta) {
if (is_forward) {
if (get_translation().y < (init_translation.y + height)) {
//move_and_collide(Vector3(0, 1, 0) * speed * delta);
set_translation(Vector3(init_translation.x, get_translation().y + speed * delta, init_translation.z));
} else {
is_forward = false;
}
} else if (!is_forward) {
if(get_translation().y > init_translation.y) {
//move_and_collide(Vector3(0, -1, 0) * speed * delta);
set_translation(Vector3(init_translation.x, get_translation().y - speed * delta, init_translation.z));
} else {
is_forward = true;
}
}
}