interpolate move will now immediately stop if destination is reached
parent
fd99159b27
commit
3df374b3b9
|
@ -171,7 +171,10 @@ void interpolate_move(object_t* object, float target_x, float target_y, float ma
|
||||||
float dx = target_x - object->sprite.x, dy = target_y - object->sprite.y;
|
float dx = target_x - object->sprite.x, dy = target_y - object->sprite.y;
|
||||||
// calculate direction x,y
|
// calculate direction x,y
|
||||||
float m = sqrtf(dx*dx + dy*dy);
|
float m = sqrtf(dx*dx + dy*dy);
|
||||||
dx /= m; dy /= m;
|
if(dx != 0)
|
||||||
|
dx /= m;
|
||||||
|
if(dy != 0)
|
||||||
|
dy /= m;
|
||||||
dx *= max_step_size; dy *= max_step_size;
|
dx *= max_step_size; dy *= max_step_size;
|
||||||
int step_count = max_step_size / m;
|
int step_count = max_step_size / m;
|
||||||
|
|
||||||
|
@ -187,7 +190,7 @@ void interpolate_move(object_t* object, float target_x, float target_y, float ma
|
||||||
* 1. move towards target
|
* 1. move towards target
|
||||||
* 2. check collision with every other object
|
* 2. check collision with every other object
|
||||||
*/
|
*/
|
||||||
for(int steps = 0; steps < step_count; ++steps) {
|
for(int steps = 0; steps < step_count && (object->sprite.x != target_x || object->sprite.y != target_y); ++steps) {
|
||||||
// move towards target, snap to target if distance is too low
|
// move towards target, snap to target if distance is too low
|
||||||
const float old_x = object->sprite.x, old_y = object->sprite.y;
|
const float old_x = object->sprite.x, old_y = object->sprite.y;
|
||||||
float new_x, new_y;
|
float new_x, new_y;
|
||||||
|
|
Loading…
Reference in New Issue