limboai/bt/actions/bt_random_wait.cpp

32 lines
888 B
C++
Raw Normal View History

2022-08-29 12:06:48 +00:00
/* bt_random_wait.cpp */
#include "bt_random_wait.h"
#include "core/math/math_funcs.h"
2022-08-29 12:06:48 +00:00
String BTRandomWait::_generate_name() const {
return vformat("Wait %s to %s sec",
Math::snapped(duration_min_max.x, 0.001),
Math::snapped(duration_min_max.y, 0.001));
2022-08-29 12:06:48 +00:00
}
void BTRandomWait::_enter() {
2022-12-17 10:26:48 +00:00
time_passed = 0.0;
duration = Math::random(duration_min_max.x, duration_min_max.y);
2022-08-29 12:06:48 +00:00
}
int BTRandomWait::_tick(float p_delta) {
2022-12-17 10:26:48 +00:00
time_passed += p_delta;
if (time_passed < duration) {
2022-08-29 12:06:48 +00:00
return RUNNING;
} else {
return SUCCESS;
}
}
void BTRandomWait::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_duration_min_max", "p_value"), &BTRandomWait::set_duration_min_max);
ClassDB::bind_method(D_METHOD("get_duration_min_max"), &BTRandomWait::get_duration_min_max);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "duration_min_max"), "set_duration_min_max", "get_duration_min_max");
}