iteration count for interpolate_move now based on number of steps required to fullfill move in theory

pull/8/head
Sara 2023-06-18 14:24:38 +02:00
parent 0a8aac2325
commit dff8e8304d
1 changed files with 2 additions and 1 deletions

View File

@ -173,6 +173,7 @@ void interpolate_move(object_t* object, float target_x, float target_y, float ma
float m = sqrtf(dx*dx + dy*dy);
dx /= m; dy /= m;
dx *= max_step_size; dy *= max_step_size;
int step_count = max_step_size / m;
// ensure this object would ever collide
// if it wouldn't collide anyway, just set position
@ -186,7 +187,7 @@ void interpolate_move(object_t* object, float target_x, float target_y, float ma
* 1. move towards target
* 2. check collision with every other object
*/
while(object->sprite.x != target_x || object->sprite.y != target_y) {
for(int steps = 0; steps < step_count; ++steps) {
// move towards target, snap to target if distance is too low
const float old_x = object->sprite.x, old_y = object->sprite.y;
float new_x, new_y;