iteration count for interpolate_move now based on number of steps required to fullfill move in theory
parent
0a8aac2325
commit
dff8e8304d
|
@ -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);
|
float m = sqrtf(dx*dx + dy*dy);
|
||||||
dx /= m; dy /= m;
|
dx /= m; 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;
|
||||||
|
|
||||||
// ensure this object would ever collide
|
// ensure this object would ever collide
|
||||||
// if it wouldn't collide anyway, just set position
|
// 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
|
* 1. move towards target
|
||||||
* 2. check collision with every other object
|
* 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
|
// 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