summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/math/a_star.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index 7e061359fc..320990cc50 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -43,6 +43,7 @@ int AStar::get_available_point_id() const {
void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) {
ERR_FAIL_COND(p_id < 0);
+ ERR_FAIL_COND(p_weight_scale < 1);
if (!points.has(p_id)) {
Point *pt = memnew(Point);
pt->id = p_id;
@@ -192,8 +193,7 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
Point *n = begin_point->neighbours[i];
n->prev_point = begin_point;
- n->distance = _compute_cost(n->id, begin_point->id);
- n->distance *= n->weight_scale;
+ n->distance = _compute_cost(begin_point->id, n->id) * n->weight_scale;
n->last_pass = pass;
open_list.add(&n->list);
@@ -221,7 +221,6 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
real_t cost = p->distance;
cost += _estimate_cost(p->id, end_point->id);
- cost *= p->weight_scale;
if (cost < least_cost) {
@@ -238,8 +237,7 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
Point *e = p->neighbours[i];
- real_t distance = _compute_cost(p->id, e->id) + p->distance;
- distance *= e->weight_scale;
+ real_t distance = _compute_cost(p->id, e->id) * e->weight_scale + p->distance;
if (e->last_pass == pass) {
//oh this was visited already, can we win the cost?